diff --git a/src/Uplink/Auth/Admin/Disconnect_Controller.php b/src/Uplink/Auth/Admin/Disconnect_Controller.php index 05c7abe4..e6dd69e7 100644 --- a/src/Uplink/Auth/Admin/Disconnect_Controller.php +++ b/src/Uplink/Auth/Admin/Disconnect_Controller.php @@ -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; } }