doutan2456 2015-12-02 10:58
浏览 21

仅向超级管理员显示css

My goal is to hide specific tables with CSS on WordPress dashboard, from all users except super admin.

<?php is_super_admin( $user_id ); ?>

add_action( 'admin_head', 'my_custom_function' );
function my_custom_function() {
 if ( ! current_user_can( 'update_core' ) ) {
   echo '<style>p.smush-status {
   display: none;
   }
   button.button.wp-smush-send  {
   display: none;
   }
   #smushit {
   display:none;
   }</style>';
 }
});

But, when I'm adding this code to mu-plugins, I got the following error:

Fatal error: Call to undefined function wp_get_current_user() in /home/.../public_html/domain.com/wp-includes/capabilities.php on line 1614

capabilities.php it's WordPress core file.

Would you please have a look and tell me how can I improve this code?

Thank you

  • 写回答

1条回答 默认 最新

  • doumi7854 2015-12-02 11:38
    关注

    Do not use css to hide part of the admin dashboard, this is a security breach. You must to unset it using a function added in your theme functions.php:

    // Create the function to use in the action hook
    
    function remove_dashboard_widgets() {
    
    
        global $wp_meta_boxes;
    
        // Remove the quickpress widget
    
        unset($wp_meta_boxes['dashboard']['side']['core']['dashboard_quick_press']);
    
        // Remove the incomming links widget
    
        unset($wp_meta_boxes['dashboard']['normal']['core']['dashboard_incoming_links']);
    } 
    
    // Hoook into the 'wp_dashboard_setup' action to register our function
    if(!is_admin()){
    add_action('wp_dashboard_setup', 'remove_dashboard_widgets' );
    }
    

    Edit: and dont edit wordpress core files aswell, you will lost everything because of update.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大