wordpress 如何移除管理后台仪表盘小工具

仪表盘的显示如下,如何禁用其中的仪表盘呢?

wordpress控制面板

 

1.找到php文件: /wp-admin/includes/dashboard.php

2.在文件最后添加以下代码:

// 创建一个动作钩子函数

function meetrice_remove_dashboard_widgets() {
    global $wp_meta_boxes;
//    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
//    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_recent_drafts']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
    unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
//    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_duoshuo']);
//    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_right_now']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_recent_comments']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
} 

// 在 'wp_dashboard_setup'动作中注册这个钩子函数

add_action('wp_dashboard_setup', 'meetrice_remove_dashboard_widgets' );

3.如何确定仪表盘的名称及类型

$wp_meta_boxes['dashboard']['仪表盘类型']['core']['仪表盘名称']

使用开发者工具查看diy的ID,就是仪表盘的名称;

而它的容器div的ID为 xxx-sortables,其中xxx即它的类型

 

另外一种 移除仪表盘的方法:

修改用户的主题中的functions.php文件,在其中加入以下代码:

<?php
function disable_default_dashboard_widgets() {

    remove_meta_box('dashboard_right_now', 'dashboard', 'core');      //概况(Right Now)
    remove_meta_box('dashboard_recent_comments', 'dashboard', 'core'); //近期评论(Recent Comments)
    remove_meta_box('dashboard_incoming_links', 'dashboard', 'core');  //链入链接(Incoming Links)
    remove_meta_box('dashboard_plugins', 'dashboard', 'core');      //插件(Plugins)

    remove_meta_box('dashboard_quick_press', 'dashboard', 'core');  //快速发布(QuickPress)
    remove_meta_box('dashboard_recent_drafts', 'dashboard', 'core'); //近期草稿(Recent Drafts)
    remove_meta_box('dashboard_primary', 'dashboard', 'core');  //WordPress China 博客(WordPress Blog)
    remove_meta_box('dashboard_secondary', 'dashboard', 'core'); //其它 WordPress 新闻(Other WordPress News)
}
add_action('admin_menu', 'disable_default_dashboard_widgets');
?>

 

也可以根据用户的权限来称除

function user_role_dashboard()
{
  global $wp_meta_boxes, $current_user;
 
  // remove incoming links info for authors or editors
  if(in_array('author', $current_user->roles) || in_array('editor',$current_user->roles))
  {
    unset($wp_meta_boxes['dashboard']['normal ']['core']['dashboard_incoming_links']);
  }
 
  // remove the plugins info and news feeds for everyone
  unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_plugins']);
  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_primary']);
  unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_secondary']);
 
}
//add our function to the dashboard setup hook
add_action('wp_dashboard_setup', 'user_role_dashboard');

 

posted @ 2013-01-05 09:34  meetrice  阅读(1708)  评论(0编辑  收藏  举报