/ Published in: PHP
Checks if a particular user has a role.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Checks if a particular user has a role. * Returns true if a match was found. * * http://codex.wordpress.org/Roles_and_Capabilities#Subscriber * http://docs.appthemes.com/tutorials/wordpress-check-user-role-function/ * http://wordpress.org/support/topic/how-to-get-the-current-logged-in-users-role * * @param string $role Role name. * @param int $user_id (Optional) The ID of a user. Defaults to the current user. * @return bool */ function appthemes_check_user_role( $role, $user_id = null ) { $user = get_userdata( $user_id ); else $user = wp_get_current_user(); return false; } // example use for the current user if ( appthemes_check_user_role( 'subscriber' ) ){ show_admin_bar(false); } else { _e( "Sorry man, no luck.", 'appthemes' ); }