Wordpress在主题中自定义登录页面而且禁用自带的登录页面

在使用Wordpress制做主题以后,不想要他自带的登录页面以及地址。php

一、新建一个用户页面来接管与登录相关的动做

//在主题根目录下新建page-login.php,经过action获取用户动做,而后进行不一样的处理。
//固然也能够只把login动做的代码放里面,其他再新建page-register.php等页面。
$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : 'login';
global $wpdb, $user_ID;
switch ($action) {
    case 'logout':
        if ($user_ID) {
            wp_logout();
            $redirect_to = apply_filters('logout_redirect', $redirect_to, $requested_redirect_to, $user);
            wp_safe_redirect($redirect_to);
        }
        exit();
    case 'forget':
        if ($user_ID) {
            wp_redirect(get_bloginfo('url'));
        } else {
            //在这里写忘记密码的处理过程
        }
        exit();
    case 'reset':
        if ($user_ID) {
            //这里写重置密码的处理过程
        } else {
            wp_redirect(wselibrary_getloginurl());
        }
        exit();
    case 'register':
        if ($user_ID) {
            wp_redirect(get_bloginfo('url'));
        } else {
            //在这里写用户注册的处理过程
        }
        exit();
    case 'login':
    default:
        if ($user_ID) {
            wp_redirect(get_bloginfo('url'));
        } else {
            //这里写用户登录的处理过程
        }
        exit();
}

二、 禁用Wordpress自带的登录页面

//原理其实很简单,就是让用户访问自带登录页面时直接跳转到指定页面
if (!function_exists('login_protection')) {
    function login_protection()
    {
        //若是有须要,你能够给本身一个访问的途径
        if ($_GET['superuser'] != 'password') header('Location: /index.php/login');
        //固然你也能够禁止全部人访问
        //header('Location: /index.php/login');
    }
    add_action('login_enqueue_scripts','login_protection');
}
相关文章
相关标签/搜索