WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to render some custom dashboard widget conditionally. If logined user have more than or equal to editor role I would like to render some more widgets than a user with subscriber role. How to do this? Any help please...

share|improve this question
up vote 1 down vote accepted
// PHP 5.3 syntax - anonymous functions (Closures)
add_action('wp_dashboard_setup', function(){
    if(current_user_can('activate_plugins')){ // Administrator
        wp_add_dashboard_widget('dbwidget-Administrator', '#Administrator', function(){
            // Print widget here
    }elseif(current_user_can('delete_others_posts')){ // Editor
        wp_add_dashboard_widget('dbwidget-Editor', '#Editor', function(){
            // Print widget here
    }elseif(current_user_can('delete_published_posts')){ // Author
        wp_add_dashboard_widget('dbwidget-Author', '#Author', function(){
            // Print widget here
    }elseif(current_user_can('edit_posts')){ // Contributor
        wp_add_dashboard_widget('dbwidget-Contributor', '#Contributor', function(){
            // Print widget here
    }elseif(current_user_can('read')){ // Subscriber
        wp_add_dashboard_widget('dbwidget-Subscriber', '#Subscriber', function(){
            // Print widget here

As you can see I chained them with elseif to ensure smooth Role degradation as Admin can do all the below too. Play with it as you wish. Learn more about Roles and Capabilities here.

share|improve this answer
thank you for your response. let me try – notme Oct 11 '11 at 5:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.