我的插件代码如下所示,
if (!current_user_can('administrator')){
function hide_post_page_options() {
//global $post;
// Set the display css property to none for add category and add tag functions
$hide_post_options = "<style type=\"text/css\"> .jaxtag { display: none; } #category-adder { display: none; } </style>";
print($hide_post_options);
}
add_action( 'admin_head', 'hide_post_page_options' );
}
但是当我激活时出现错误
Fatal error: Call to undefined function wp_get_current_user()
我可以通过将pluggable.php包含在capability.php中来解决这个问题。但我不认为对这些文件进行更改是更好的方法。由于 wp_get_current_user() 是一个可插入函数,因此仅在加载插件后才可用。有没有办法在不更改核心文件的情况下使用它?
最佳答案
我建议您不要使用CSS隐藏它,如果它不是管理员,我建议您将其从菜单中删除,这将是WordPress的方法
add_action('admin_menu', 'dot1_remove_dahsboard_menu', 111);
function dot1_remove_dahsboard_menu(){
global $submenu, $menu;
//to check array key you want to unset in your case, print the array
echo "<pre>";
print_r($menu);
echo "</pre>";
echo "<pre>";
print_r($submenu);
echo "</pre>";
/* Unset menu array */
if( !current_user_can('manage_options') ){
unset($menu['10']);
}
/* Unset submenu array */
if( !current_user_can('manage_options') ){
unset($submenu['edit.php']['10']);
}
}
关于php - 在 WordPress 中实现插件加载 Action 钩子(Hook),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19803502/