Php 在wordpress中实现插件加载的动作钩子

Php 在wordpress中实现插件加载的动作钩子,php,wordpress,Php,Wordpress,我的插件代码如下所示 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 { dis

我的插件代码如下所示

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

我可以通过在capabilities.php中包含pluggable.php来解决这个问题。但我不认为对这些文件进行更改是更好的方法。由于wp_get_current_user()是一个可插入函数,因此只有在加载插件后才可用。有没有一种方法可以在不更改核心文件的情况下使用它?

与其用CSS隐藏它,我建议您将它从菜单中删除,如果它不是admin,这将是一种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']);
  }
}
add_action('admin_menu','dot1_remove_dahsboard_menu',111);
功能dot1_移除_dahsboard_菜单(){
全局$子菜单,$菜单;
//要检查要在案例中取消设置的数组键,请打印数组
回声“;
打印(菜单);
回声“;
回声“;
打印(子菜单);
回声“;
/*取消设置菜单数组*/
如果(!当前用户可以('manage_options')){
取消设置($menu['10']);
}
/*取消设置子菜单数组*/
如果(!当前用户可以('manage_options')){
取消设置($子菜单['edit.php']['10']);
}
}

您是否尝试使用此函数
get_currentuserinfo()?停用其余插件并检查。若并没有得到错误,那个么找出哪些插件是冲突的。特别检查“多站点插件管理器”。这不起作用,因为您应该检查回调函数中的用户功能(而不是角色)。无论如何,我更喜欢布姆希瓦的方法。你的答案中有一些重复的代码。另外,检查一下。你的重复应该是其他的,而且我已经更新了当前的\u user\u can参数,谢谢你指出:)
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']);
  }
}