If you are wondering, How to check weather logged in user is subscriber or not? then keep reading this post. Time and again you need to check if the current logged in user is subscriber, editor, administrator, or any other roles. We can use the code below, to check weather the logged in user is subscriber or not.
<?php global $current_user; // Use global get_currentuserinfo(); // Make sure global is set, if not set it. if ( ! user_can( $current_user, "subscriber" ) ) // Check user object has not got subscriber role echo 'User is a not Subscriber'; else echo 'User is a Subscriber'; ?>
get_currentuserinfo() retrieves the information pertaining to the currently logged in user, and places it in the global variable $userdata. Properties map directly to the wp_users table in the database.
Also places the individual attributes into the following separate global variables:
- $user_url (User’s website, as entered in the user’s Profile)
- $user_pass_md5 (A md5 hash of the user password — a type of encoding that is very nearly, if not entirely, impossible to decode, but useful for comparing input at a password prompt with the actual user password.)
- $display_name (User’s name, displayed according to the ‘How to display name’ User option)