2015-12-02 110 views
0

我的目标是隐藏WordPress超级管理员以外的所有用户使用CSS仪表板上的CSS。只向超级管理员显示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-插件,我得到了以下错误:

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它的WordPress的核心文件。

请您看看并告诉我如何改进此代码?

谢谢

+0

你读过这个吗? *对于WordPress版本<3.4:使用init或任何后续操作来调用此函数。在行动之外调用它可能会导致麻烦。详情请参见[#14024](http://core.trac.wordpress.org/ticket/14024)。* –

+0

我没有进入Wordpress,只是使用CSS隐藏非管理员的关键事物似乎不是正确的办法。客户可以改变所有的CSS。如果您确定需要这样做,那么如何为层次结构中的元素添加类(“admin”),并将所有其他元素作为CSS选择器中的后代元素(例如“.admin #smushit”)? –

回答

0

不要使用CSS来隐藏管理仪表板的一部分,这是一个安全漏洞。 必须使用你的主题的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'); 
} 

编辑:和不编辑WordPress的核心文件藏汉,你会丢失,因为更新的一切。

+0

谢谢Bipbip,我不知道使用css隐藏管理仪表板的一部分,这是一个安全漏洞。那我不会用这个。然后我可以用一个插件封装(?)一个代码,调用在仪表板中显示一些统计信息,只能查看超级管理员? – Nastia

+0

检查函数,只有在用户不是管理员的情况下才能调用,您可以将其粘贴到您的主题中的fonctions.php中,并且如果您使用插件的参数替换参数,则应该可以工作。 – Bipbip

相关问题