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');

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值