2013-05-28 88 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,不客气:-) –

相关问题