gpt4 book ai didi

php - 仅向 super 管理员显示 css

转载 作者:行者123 更新时间:2023-11-28 06:46:03 25 4
gpt4 key购买 nike

我的目标是在 WordPress 仪表板上使用 CSS 隐藏特定表格,除了 super 管理员之外的所有用户。

<?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-plugins 时,出现以下错误:

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

请你看看并告诉我如何改进这段代码好吗?

谢谢

最佳答案

不要使用 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 核心文件,因为更新你会丢失所有内容。

关于php - 仅向 super 管理员显示 css,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34041043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com