How to Check User Role in WordPress
Filed under Labs
If you are a WordPress developer then sometimes you need to check a role of a user, for example you want to show particular link to only for registered authors and not for common visitors then the bellow WordPress snippet will help you fine.
<?php
/**
* Check User Role in WordPress
*
*/
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
}
?> |
Posts you may like:
Awaken magazine/news WordPress theme
Awaken WordPress theme is an elegant magazine/news WordPress theme. It has a magazine layout with …
Onetone WordPress business theme
Onetone is a one-page business theme based on Bootstrap framework and coded with HTML5/CSS3. All …
AppsWorld – WP Landing Page Theme
AppsWorld is a fully responsive app landing page theme for WordPress. If you want to …
Customizr free WordPress theme
Customizr is a free WP theme which is very easy to customize as the name …
Auberge free restaurant and cafe WordPress theme
Auberge is a modern responsive, retina-ready restaurant and cafe theme for WordPress websites. Auberge supports …