wp_login_url redirects me always to wp-admin - Hack The Tech - Latest News related to Computer and Technology

Hack The Tech - Latest News related to Computer and Technology

Get Daily Latest News related to Computer and Technology and hack the world.

Thursday, April 27, 2023

wp_login_url redirects me always to wp-admin

I have a specific site on my website which needs to be logged in. So if I visit the page and I am not logged in, I want to redirected to wp-loginand back to the page. But everything I am trying, I will always redirected to wp-admin

That is one of my failures:

add_action( 'template_redirect', [ $this, 'redirect_to_login_page' ] );
public function redirect_to_login_page() {
        if ( ! is_user_logged_in() && strpos( $_SERVER['REQUEST_URI'], '/test' ) !== false ) {
            $login_url = add_query_arg( 'redirect_to', site_url( '/test' ), wp_login_url() );
            wp_redirect( $login_url );
            exit;
        }
    }

What can I do?



source https://stackoverflow.com/questions/76076099/wp-login-url-redirects-me-always-to-wp-admin

No comments:

Post a Comment