• Posted: 2011-07-11
  • Author: Filip Stefansson
  • Tags:

Check user role

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
<?php
if( current_user_can('editor') ) {
    // true if user is an editor
}

if( !current_user_can('administrator') ) {
    // true if user is not admin
}

if( current_user_can('edit_posts') ) {
    // true if user can edit posts
}
?>

Instructions:

Sometimes you might want to know what role a user have, for example if you only want certain links(like edit etc) to be displayed for authors and not for visitors.

The function current_user_can() does just that. See the examples below:

There is a ton of different capabilities you can check for, and they are all found in the documentation.


Related links:
http://codex.wordpress.org/Roles_and_Capabilities
Share this snippet

If you like this snippet, share it with friends!