安装Query Monitor 检查哪些脚本以及它们为您的角色使用的挂钩。请记住,这些脚本可能具有依赖性。
您可能应该从Dashboard Widgets API.
仪表板上默认小部件的名称:
// Main column (left):
$wp_meta_boxes[\'dashboard\'][\'normal\'][\'high\'][\'dashboard_browser_nag\']
$wp_meta_boxes[\'dashboard\'][\'normal\'][\'core\'][\'dashboard_right_now\']
$wp_meta_boxes[\'dashboard\'][\'normal\'][\'core\'][\'dashboard_activity\']
// Side Column (right):
$wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'][\'dashboard_quick_press\']
$wp_meta_boxes[\'dashboard\'][\'side\'][\'core\'][\'dashboard_primary\']
至
remove all 基于用户角色的小部件:
function remove_dashboard_meta() {
// get the current user
$user = wp_get_current_user();
// define roles that cannot see the widgets
$blacklisted_roles = array(\'subscriber\');
// remove if the current user has a blacklisted role
if( array_intersect($blacklisted_roles, $user->roles ) ) {
remove_meta_box( \'dashboard_incoming_links\', \'dashboard\', \'normal\' );
remove_meta_box( \'dashboard_plugins\', \'dashboard\', \'normal\' );
remove_meta_box( \'dashboard_primary\', \'dashboard\', \'side\' );
remove_meta_box( \'dashboard_secondary\', \'dashboard\', \'normal\' );
remove_meta_box( \'dashboard_quick_press\', \'dashboard\', \'side\' );
remove_meta_box( \'dashboard_recent_drafts\', \'dashboard\', \'side\' );
remove_meta_box( \'dashboard_recent_comments\', \'dashboard\', \'normal\' );
remove_meta_box( \'dashboard_right_now\', \'dashboard\', \'normal\' );
remove_meta_box( \'dashboard_activity\', \'dashboard\', \'normal\');//since 3.8
}
}
add_action( \'admin_init\', \'remove_dashboard_meta\' );
要将脚本出列,您可以结合使用以下功能:
function remove_admin_scripts( ) {
// if ( \'edit.php\' != $hook ) {
// return;
// }
// get the current user
$user = wp_get_current_user();
// define roles that cannot see the widgets
$blacklisted_roles = array(\'subscriber\');
// get out of this function if the blacklisted roles are now found
if( ! array_intersect($blacklisted_roles, $user->roles ) ) {
return;
}
$jquery_ui = array (
"jquery-ui-widget",
"jquery-ui-mouse",
"jquery-ui-accordion",
"jquery-ui-autocomplete",
"jquery-ui-slider",
"jquery-ui-tabs",
"jquery-ui-draggable",
"jquery-ui-droppable",
"jquery-ui-selectable",
"jquery-ui-position",
"jquery-ui-datepicker",
"jquery-ui-resizable",
"jquery-ui-dialog",
"jquery-ui-button",
);
foreach ( $jquery_ui as $script ) {
wp_deregister_script( $script );
}
}
add_action( \'admin_enqueue_scripts\', \'remove_admin_scripts\' );