add user status in user table admin side

Posted: June 19, 2015 in Uncategorized

this code is used when we want to varify user status whenever user login..and we can easily make changes from Approve to Unapprove and vicevarsa.
image_user_status
NOW, My strategy is when user register, just add “user_status” key as “Unapprove” in wp_usermeta table.now when user login we need to check “user_status” from table

Step 1 :Download file from here and unzip it and put in theme folder.
Step 2 :Add The file in your function.php in active theme folder.

require_once(get_template_directory().’/vd_lib/vd_set_user_status.php’);

Step 3 :Now at login process,we want to allow login to those users who has “user_status” as approved in wp_usermeta table…for that we need to add filter called ‘authenticate’.for that add following code in function.php

function check_user_status($user, $username, $password) {
if (in_array( ‘subscriber’, (array) $user->roles ) ) {
if (get_user_meta($user->ID, ‘user_status’, true) == ‘Approve’) { return $user; }
else{ return new WP_Error(‘Account Not Active.’); }
}
else{ return $user; }
}
add_filter(‘authenticate’,’check_user_status’, 30, 3);

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s