diff --git a/lib/sso-provider/discourse-sso.php b/lib/sso-provider/discourse-sso.php index 5db44c58..0b23dccf 100644 --- a/lib/sso-provider/discourse-sso.php +++ b/lib/sso-provider/discourse-sso.php @@ -51,16 +51,20 @@ public function sync_sso_record( $user_login, $user ) { $bypass_sync = apply_filters( 'wpdc_bypass_sync_sso', false, $user->ID, $user ); if ( ! $bypass_sync ) { - // Make sure the login hasn't been initiated by clicking on a SSO login link. - $query_string = wp_parse_url( wp_get_referer(), PHP_URL_QUERY ); - $query_params = array(); - parse_str( $query_string, $query_params ); - $sso_referer = ! empty( $query_params['redirect_to'] ) && preg_match( '/^\/\?sso/', $query_params['redirect_to'] ); - if ( ! $sso_referer ) { - $params = $this->get_sso_params( $user ); - - $this->sync_sso( $params, $user->ID ); - } + // Make sure the login hasn't been initiated by clicking on a SSO login link. + $query_string = wp_parse_url( wp_get_referer(), PHP_URL_QUERY ); + $query_params = array(); + $sso_referer = null; + + if ( ! empty( $query_string ) ) { + parse_str( $query_string, $query_params ); + $sso_referer = ! empty( $query_params['redirect_to'] ) && preg_match( '/^\/\?sso/', $query_params['redirect_to'] ); + } + + if ( ! $sso_referer ) { + $params = $this->get_sso_params( $user ); + $this->sync_sso( $params, $user->ID ); + } } return null; @@ -257,11 +261,11 @@ protected function handle_error( $type, $args = array() ) { return new \WP_Error( $type, isset( $args['message'] ) ? $args['message'] : 'SSO error' ); } - /** - * Handle redirects - * - * @param string $url Url to redirect to. - */ + /** + * Handle redirects + * + * @param string $url Url to redirect to. + */ public function redirect_to( $url ) { wp_safe_redirect( esc_url_raw( $url ) ); exit;