Skip to content

Commit

Permalink
Fix calling build method within ajax request
Browse files Browse the repository at this point in the history
  • Loading branch information
tarecord committed Sep 13, 2024
1 parent fde8e11 commit 85ec045
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Uplink/Auth/Auth_Url_Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public function build( string $slug, string $domain = '' ): string {
return '';
}

$callback_url = $pagenow;

// If building the URL in an ajax context, use the referring URL.
if ( wp_parse_url( $pagenow, PHP_URL_PATH ) === 'admin-ajax.php' ) {
$callback_url = wp_get_referer();
}

$auth_url = $this->auth_url_manager->get( $slug );

if ( ! $auth_url ) {
Expand All @@ -69,7 +76,7 @@ public function build( string $slug, string $domain = '' ): string {

$url = add_query_arg(
array_filter( array_merge( $_GET, $args ) ),
admin_url( $pagenow )
admin_url( $callback_url )
);

return sprintf( '%s?%s',
Expand Down

0 comments on commit 85ec045

Please sign in to comment.