how to render dashboard widgets conditionaly in wordpress admin

// 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.

techhipbettruvabetnorabahisbahis forumutaraftarium24edueduseduseduseduseduedueduedusedu