【发布时间】:2013-11-17 04:24:28
【问题描述】:
我的插件代码如下所示,
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()
我可以通过在capabilities.php 中包含pluggable.php 来解决这个问题。但我不认为对这些文件进行更改是更好的方法。因为 wp_get_current_user() 是一个可插入的函数,所以它只有在插件加载后才可用。有没有办法在不更改核心文件的情况下使用它?
【问题讨论】:
-
您是否尝试过使用此功能
get_currentuserinfo();? -
停用其余插件并检查。如果您没有收到错误,请查找哪些插件存在冲突。特别勾选“Multisite Plugin Manager”。
-
这不起作用,因为您应该检查用户capability(不是角色)inside回调函数.无论如何,我更喜欢 boomShiva 的方法。