// 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
});
}
});
正如您所见,我将它们与elseif链接起来,以确保角色顺利降级,因为管理员也可以完成以下所有操作。随心所欲地玩吧。了解更多有关
Roles and Capabilities here.