please help, I have to restrict some users based on the value of some metadata.for eg:if the account is not verified by admin(a metafield like "adminveri" will be zero), then the user should not login....please help me..
this is what i have done so far... add_filter('authenticate', 'check_login', 100, 3);
function check_login($user,$username,$password,$uid)
{
if(!empty($user)) $user_data=$user->data;
$adminveri=get_user_meta($uid,'admin_status');
$emailveri=get_user_meta($uid,'email_status');
if($adminveri[0]==0) or $emailveri[0]==0 )
{
return null;
}
else
{
return $user;
}
}
this code dont allow anyone to login...Also what is the difference between add_filter and add_action?
please help, I have to restrict some users based on the value of some metadata.for eg:if the account is not verified by admin(a metafield like "adminveri" will be zero), then the user should not login....please help me..
this is what i have done so far... add_filter('authenticate', 'check_login', 100, 3);
function check_login($user,$username,$password,$uid)
{
if(!empty($user)) $user_data=$user->data;
$adminveri=get_user_meta($uid,'admin_status');
$emailveri=get_user_meta($uid,'email_status');
if($adminveri[0]==0) or $emailveri[0]==0 )
{
return null;
}
else
{
return $user;
}
}
this code dont allow anyone to login...Also what is the difference between add_filter and add_action?
Share Improve this question edited Sep 5, 2013 at 4:46 Arjun asked Sep 4, 2013 at 17:28 ArjunArjun 32 bronze badges 1- What have you tried so far? Show us your code. Spend a little more time forming a well-written question if you want someone to spend time helping you please. – GhostToast Commented Sep 4, 2013 at 18:51
1 Answer
Reset to default 1Add the folowing to your themes's functions.php file.
add_action( 'wp_login', 'wpse_112895_validate_user', 10, 2 );
function wpse_112895_validate_user( $login, $user ) {
$meta = get_user_meta( $user->ID, 'adminveri', true );
// not verified, log them out!
if ( $meta != 0 )
wp_logout();
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745394810a4625829.html
评论列表(0条)