vapvarun icon

Secure Login Redirection: Redirect wp-login.php to /login with Elementor Compatibility

vapvarun | PRO | 12/12/23 06:50:54 AM UTC (Edited) | 0 ⭐ | 1904 👁️ | Never ⏰ | []
PHP |

920 B

|

Software

|

0 👍

/

0 👎

// Redirect wp-login.php to the custom login page
function wbcom_custom_login_redirect($redirect_to, $request, $user) {
    // Is there a user to check?
    if (isset($user->roles) && is_array($user->roles) && in_array('subscriber', $user->roles)) {
        // Redirect them to the default place
        return home_url('/login'); // Updated to use /login
    } else {
        return $redirect_to;
    }
}
add_filter('login_redirect', 'wbcom_custom_login_redirect', 10, 3);
 
// Redirect non-logged-in users accessing wp-login.php
function wbcom_redirect_non_logged_in_users() {
    if (!is_user_logged_in() && strpos($_SERVER['REQUEST_URI'], 'wp-login.php') !== false && !isset($_POST['wp-submit']) && !defined('DOING_AJAX')) {
        $custom_login_url = home_url('/login'); // Updated to use /login
        wp_redirect($custom_login_url);
        exit;
    }
}
add_action('init', 'wbcom_redirect_non_logged_in_users');
 

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎

    
        
  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎