Make Dashboard widgets only visible to administrator


Description: 

You can add the following code to your function.php file to make your widget visible only to admin.




Kind:

PHP


PHP:

global $current_user;
if(!empty($current_user)){
$roles = $current_user->roles;
$role = array_shift($roles);
if($role != ‘administrator’){
add_action(‘wp_dashboard_setup’, ‘remove_dashboard_widgets’);
}

}

function remove_dashboard_widgets() {
global $wp_meta_boxes;
unset($wp_meta_boxes[‘dashboard’][‘normal’][‘core’][‘wpms_dashboard_widget’]);
}


URL: