diff --git a/WP_Auth0.php b/WP_Auth0.php index 58d024fe..e314210e 100644 --- a/WP_Auth0.php +++ b/WP_Auth0.php @@ -372,6 +372,18 @@ public function render_auth0_login_css() { return; } + // If the user has a WP session, determine where they should end up and redirect. + if ( is_user_logged_in() ) { + $login_redirect = empty( $_REQUEST['redirect_to'] ) ? + $this->a0_options->get( 'default_login_redirection' ) : + filter_var( $_REQUEST['redirect_to'], FILTER_SANITIZE_URL ); + + // Add a cache buster to avoid an infinite redirect loop on pages that check for auth. + $login_redirect = add_query_arg( time(), '', $login_redirect ); + wp_safe_redirect( $login_redirect ); + exit; + } + wp_enqueue_style( 'auth0', WPA0_PLUGIN_CSS_URL . 'login.css', false, WPA0_VERSION ); } @@ -397,18 +409,6 @@ public function render_form( $html ) { return $html; } - // If the user has a WP session, determine where they should end up and redirect. - if ( is_user_logged_in() ) { - $login_redirect = empty( $_REQUEST['redirect_to'] ) ? - $this->a0_options->get( 'default_login_redirection' ) : - filter_var( $_REQUEST['redirect_to'], FILTER_SANITIZE_URL ); - - // Add a cache buster to avoid an infinite redirect loop on pages that check for auth. - $login_redirect = add_query_arg( time(), '', $login_redirect ); - wp_safe_redirect( $login_redirect ); - exit; - } - ob_start(); require_once WPA0_PLUGIN_DIR . 'templates/login-form.php'; renderAuth0Form(); diff --git a/tests/testRenderForm.php b/tests/testRenderForm.php index b21fc203..ceec420b 100644 --- a/tests/testRenderForm.php +++ b/tests/testRenderForm.php @@ -106,7 +106,7 @@ public function testThatLoggedInUserIsRedirected() { // Use the default login redirection. $caught_exception = false; try { - self::$wp_auth0->render_form( self::$html ); + self::$wp_auth0->render_auth0_login_css(); } catch ( Exception $e ) { $err_msg = unserialize( $e->getMessage() ); $caught_exception = 0 === strpos( $err_msg['location'], 'http://example.org' ) && 302 === $err_msg['status']; @@ -118,7 +118,7 @@ public function testThatLoggedInUserIsRedirected() { $caught_exception = false; try { - self::$wp_auth0->render_form( self::$html ); + self::$wp_auth0->render_auth0_login_css(); } catch ( Exception $e ) { $err_msg = unserialize( $e->getMessage() ); $caught_exception = 0 === strpos( $err_msg['location'], $_REQUEST['redirect_to'] ) && 302 === $err_msg['status'];