Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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
    
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 Sep 4 '13 at 18:51
add comment

1 Answer

up vote 1 down vote accepted

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();
}
share|improve this answer
    
thanks for your response...but the wp_logout() is not working,ie anyone can login...if i use "return null;",any user including admin couldn't login... –  Arjun Sep 5 '13 at 5:50
    
How did you test to know it is not working? Did you do a var_dump after the condition $meta != 0? This is to know if that conditional even fires. Also you didn't mention about admin logins before so this code obviously is generic. You can further filter out the admin so this code doesn't affect them even if they don't have that meta value –  splashingpixels Sep 5 '13 at 12:08
    
thanks buddy...it worked great... –  Arjun Sep 6 '13 at 5:58
    
Please accept this answer by checking the check mark if it works for you. –  splashingpixels Sep 6 '13 at 18:24
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.