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');
}
相關文章
相關標籤/搜索