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: