Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement