Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the meaning of 1 in user status field of wp_users in wordpress CMS?

Tags:

wordpress

We are using wordpress for your website development. User is active when user_status=2 and user is inactive if user_status=0. Then what is the meaning of user_status=1.

Please provide your valuable suggestions.

like image 274
chandra sekhar Avatar asked May 11 '15 05:05

chandra sekhar


2 Answers

Here are what each user_status means:

user_status = 0 => false or normal status

user_status = 1 => User marked as spammer

user_status = 2 => User pending (user account not activated yet)

like image 105
kuroyza Avatar answered Oct 24 '22 03:10

kuroyza


https://wordpress.org/support/topic/what-is-the-status-of-user_status

The user_status field is effectively a dead record in the database. It's been that way for some time.

You could certainly make use of it for your own purpose, but as it is a sort of deprecated or unusued element, it's always possible it will be dropped from a future version of WordPress. Or even be put back to work.

Unfortunately, WordPress doesn't provide native online/offline user status methods. You'll have to implement it by yourself. Some ideas how to implement it right, could be found in that topic: https://wordpress.stackexchange.com/q/34429/44533

Another option is to use some 3rd-party plugin ( I can't advice any...).

In my own solution, I'm creating user_login custom filed in wp_usermeta table, to check user status.

//Creating hooks for login/logout actions:
add_action('clear_auth_cookie', array('WP_Plugin_Template','set_user_logged_out'), 10);
add_action('wp_login', array('WP_Plugin_Template','set_user_logged_in'), 10, 2);

//When hook is triggered, I'm using user_meta to update user status:
function set_user_logged_in($user_login, $user) {
    if(get_user_meta($user->ID, "logged_in", true) !== "true")
    if(!update_user_meta($user->ID, 'logged_in', 'true'))
    wp_die("Failed to add usermeta ", "Fatal");
}
function set_user_logged_out() {
    $user = wp_get_current_user();
    if(get_user_meta($user->ID, "logged_in", true) !== "false")
    if(!update_user_meta($user->ID, 'logged_in', 'false'))
    wp_die("Failed to add usermeta ", "Fatal");
}

Hope it helps.

like image 31
Samuel Avatar answered Oct 24 '22 04:10

Samuel