[Defender Pro] Defender Pro: re-direct mask login area when admin is logged in


We would like to use the mask login area option in Defender Pro.

Everything works except for one little issue. When the user is logged in and you go to your custom backend url it does not re-direct you to dashboard like default WP does. It instead re-directs you to login page again.

Bug or are we missing something?


  • Ash
    • WordPress Hacker

    Hello Menno

    Currently defender follows the default wordpress rule, like if you are logged in and still go to wp-login.php, it shows the login form. Please more that, defender is masking login URL not the admin URL.

    But as a workaround, you can use the following code:

    add_action( 'login_init', function() {
        $requestPath = \WP_Defender\Module\Advanced_Tools\Component\Mask_Api::getRequestPath();
        $settings    = \WP_Defender\Module\Advanced_Tools\Model\Mask_Settings::instance();
        if ( '/' . ltrim( $settings->maskUrl, '/' ) == $requestPath ) {
            if( is_user_logged_in() ) {
                wp_redirect( admin_url( '/' ) );
    } );

    You can use the code as mu-plugins: https://premium.wpmudev.org/manuals/wpmu-manual-2/using-mu-plugins/

    Hope it helps! Let us know if it works for you :slight_smile:


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.