Using user_status in conditional with get_users to return existing users

I’m working on a plugin needing to return avatars a specific way. If the user exists in the wp_users table the code is run else a different set of code is run if the user is not in the wp_users table. I cannot use the username_exist and am tinkering now with the idea of using the user_status value of 0.

From the Codex, code is possible to return information based on the user_status

Read More
$blogusers = get_users('user_status=0');
foreach ($blogusers as $user) {
    echo '<li>' . $user->user_email . '</li>';
}

This returns the email address for the users in the wp_users table.

But I want to use a conditional…

The following works on a local development server in which $id is 1. But not everyone using the plugin will have just this one user id …

if ( $id == '1' ) {
    // echo 'User ID is ' . $id;
    // Do something here
} else {
    // the user is not in WordPress do something cool   
}

How can I use the user_status in a conditional to check if the user_status is 0 then do something else run the code the user not being in the WP users table.

In other words, how can I write a conditional to check user_status = 0?

Related posts

2 comments

  1. $blogusers = get_users();
    foreach ($blogusers as $user) {
        if($user->user_status=='0'){
            //do something
        } 
        else{
            // do something else
        }   
    }
    
  2. Did you try username_exists

    <?php  
           $username = $_POST['username'];
    
           // Check if username exist in wp_users table.
           if ( username_exists( $username ) ) {
               echo "Username In Use!";
           } else {
               echo "Username Not In Use!";
           }
    ?>
    

Comments are closed.