diff --git a/dt-login/login-functions.php b/dt-login/login-functions.php index 76f8b05ff8..69c3cc06a1 100644 --- a/dt-login/login-functions.php +++ b/dt-login/login-functions.php @@ -6,23 +6,39 @@ // LOGIN PAGE REDIRECT add_action( 'init', 'dt_login_redirect_login_page' ); function dt_login_redirect_login_page() { + if ( dt_is_rest() ) { + return; + } - $login_page_enabled = DT_Login_Fields::get( 'login_enabled' ) === 'on'; if ( isset( $_SERVER['REQUEST_URI'] ) && !empty( $_SERVER['REQUEST_URI'] ) ) { - $page_viewed = substr( basename( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ), 0, 12 ); $parsed_request_uri = ( new DT_URL( sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) ) )->parsed_url; $page_viewed = ltrim( $parsed_request_uri['path'], '/' ); + //this section only applies to the login pages (ones that have the action query param) + if ( $page_viewed !== 'wp-login.php' && !isset( $_GET['action'] ) ){ + return; + } + if ( $page_viewed == 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] === 'register' && !dt_can_users_register() ) { wp_redirect( wp_login_url() ); exit; } + $login_page_enabled = DT_Login_Fields::get( 'login_enabled' ) === 'on'; if ( !$login_page_enabled ) { return; } + if ( is_user_logged_in() ){ + if ( $page_viewed == 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] === 'logout' ) { + wp_redirect( dt_login_url( 'logout' ) ); + exit; + } else { + return; + } + } + //if ( $page_viewed == 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] === 'rp' ) { // return; //} @@ -32,11 +48,6 @@ function dt_login_redirect_login_page() { exit; } - if ( $page_viewed == 'wp-login.php' && isset( $_GET['action'] ) && $_GET['action'] === 'logout' ) { - wp_redirect( dt_login_url( 'logout' ) ); - exit; - } - $login_url = DT_Login_Fields::get( 'login_url' ); $login_url = apply_filters( 'dt_login_url', $login_url ); if ( $page_viewed == $login_url && isset( $_GET['action'] ) && $_GET['action'] === 'register' && !dt_can_users_register() ) { diff --git a/dt-login/login-page.php b/dt-login/login-page.php index 7c1ef16561..5451b76619 100644 --- a/dt-login/login-page.php +++ b/dt-login/login-page.php @@ -20,6 +20,10 @@ public function __construct() { parent::__construct(); $url = dt_get_url_path(); + if ( is_user_logged_in() && strpos( $url, 'action' ) === false ) { + return; + } + $login_page_enabled = DT_Login_Fields::get( 'login_enabled' ) === 'on'; $login_url = DT_Login_Fields::get( 'login_url' );