custom field - help for user login

please help,I have to restrict some users based on the value of some metadata.for eg:if the account is not verified by

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
Add a comment  | 

1 Answer 1

Reset to default 1

Add 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

相关推荐

  • custom field - help for user login

    please help,I have to restrict some users based on the value of some metadata.for eg:if the account is not verified by

    5小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信