内置仪表板小部件没有标记,您必须使用固定列表:
\'dashboard_right_now\',
\'dashboard_plugins\',
\'dashboard_quick_press\',
\'dashboard_recent_drafts\',
\'dashboard_recent_comments\',
\'dashboard_incoming_links\',
\'dashboard_primary\',
\'dashboard_secondary\'
因此,您的代码应该测试当前小部件是否在该列表中,如果不在该列表中,则删除该小部件:
add_action(
\'wp_dashboard_setup\',
\'t5_remove_custom_dashboard_widgets\',
11
);
function t5_remove_custom_dashboard_widgets()
{
global $wp_meta_boxes;
$builtin = array (
\'dashboard_right_now\',
\'dashboard_plugins\',
\'dashboard_quick_press\',
\'dashboard_recent_drafts\',
\'dashboard_recent_comments\',
\'dashboard_incoming_links\',
\'dashboard_primary\',
\'dashboard_secondary\'
);
if ( empty ( $wp_meta_boxes[\'dashboard\'] ) )
return;
$widget_groups = $wp_meta_boxes[\'dashboard\'];
foreach ( $widget_groups as $section => $widget_group )
foreach ( $widget_group as $widgets )
foreach ( $widgets as $id => $widget )
if ( ! in_array( $id, $builtin ) )
remove_meta_box( $id, \'dashboard\', $section );
}