Check user role

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.

Code Snippet:

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

Posted in Conditional