2013-05-28 86 views
0

如何讓WordPress在登錄前檢查usermeta值?登錄前檢查用戶是否已激活

我想檢查用戶是否被激活,如果沒有激活,然後將他重定向到其他頁面。 我知道如何從數據庫中讀取usermeta值,我可以檢查它是真的還是假的,但是我需要在WordPress中插入我的代碼還是如何?

回答

2

你可以試試這個,粘貼此代碼在你的主題functions.php

function check_login($user, $username, $password) { 
    if(empty($username)) { 
     // wp_redirect(...); 
     exit; 
    } 
    $user = get_userdatabylogin($username); 
    // now check if user is allowed 
    if(/* if not allowed */) { 
     // wp_redirect(...); 
     exit; 
    } 
    return $user; 
} 
add_filter('authenticate', 'check_login', 99, 3); 
+0

這真是棒極了!謝謝。 – Jigberto

+0

@Jigberto,不客氣:-) –

相關問題