Skip to content

Commit

Permalink
Add clarification on disconnect redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
defunctl committed Oct 19, 2023
1 parent 2930694 commit 1e23b14
Showing 1 changed file with 30 additions and 14 deletions.
44 changes: 30 additions & 14 deletions src/Uplink/Auth/Admin/Disconnect_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,22 +66,38 @@ public function maybe_disconnect(): void {
);
}

$referrer = wp_get_referer();

if ( $referrer ) {
$referrer = remove_query_arg(
[
Connect_Controller::TOKEN,
Connect_Controller::LICENSE,
Connect_Controller::SLUG,
Connect_Controller::NONCE,
],
$referrer
);
$this->maybe_redirect_back();
}

wp_safe_redirect( esc_url_raw( $referrer ) );
exit;
/**
* Attempts to redirect the user back to their previous dashboard page while
* ensuring that any "Connect" token query variables are removed if they immediately
* attempt to Disconnect after Connecting. This prevents them from automatically
* getting connected again if the nonce is still valid.
*
* This will ensure the Notices set above are displayed.
*
* @return void
*/
private function maybe_redirect_back(): void {
$referer = wp_get_referer();

if ( ! $referer ) {
return;
}

$referer = remove_query_arg(
[
Connect_Controller::TOKEN,
Connect_Controller::LICENSE,
Connect_Controller::SLUG,
Connect_Controller::NONCE,
],
$referer
);

wp_safe_redirect( esc_url_raw( $referer ) );
exit;
}

}

0 comments on commit 1e23b14

Please sign in to comment.