仅向超级管理员显示css


Show css to super admin only

我的目标是在WordPress面板上用CSS隐藏特定的表,不让除超级管理员之外的所有用户使用。

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

但是,当我将此代码添加到mu插件时,我得到了以下错误:

致命错误:调用中未定义的函数wp_get_current_user()/主页//public_html/domain.com/wp-includes/cabilities.php联机1614

capabilities.php这是WordPress的核心文件。

你能看看并告诉我如何改进这个代码吗?

感谢

不要使用css隐藏管理面板的一部分,这是一种安全漏洞。您必须使用主题函数中添加的函数取消设置。hp:

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

编辑:也不要编辑wordpress的核心文件,你会因为更新而失去一切。