zoukankan      html  css  js  c++  java
  • 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');
  • 相关阅读:
    C语言寒假大作战04
    C语言寒假大作战03
    C语言寒假大作战02
    C语言寒假大作战01
    C语言I作业12—学期总结
    C语言I博客作业11
    C语言I博客作业10
    预习非数值数据的编码方式
    计算机组成与系统结构作业01
    C语言||作业01
  • 原文地址:https://www.cnblogs.com/meetrice/p/2845188.html
Copyright © 2011-2022 走看看