1

我有一个自定义分类法,如果当前用户是管理员,有没有办法只在仪表板中显示它?我需要一些类似的东西,但它不起作用:

 global $current_user;
 global $showui;
     if($current_user->roles[0] == 'administrator') {
       $showui = true;
     }  
     else {
           $showui = false;
          }
//Custom Industry Taxonomy Code (For Projects CPT)
register_taxonomy('servicecategory',
    array ( 0 => 'servicecategory',),
    array( 'hierarchical' => true, 
            'label' => 'Specialties',
            'show_ui' => $showui,
            'query_var' => true,
            'rewrite' => true,
            'show_in_nav_menus' => true,
            'show_admin_column' => true,                
            'singular_label' => 'Menu'
        ) 
    );  
4

2 回答 2

3

您可以首先命名管理此分类的能力。然后将功能添加到管理员,如下所示:

register_taxonomy('servicecategory',
    array ( 0 => 'servicecategory',),
    array( 'hierarchical' => true, 
            'label' => 'Specialties',
            'show_ui' => true,
            'query_var' => true,
            'rewrite' => true,
            'show_in_nav_menus' => true,
            'show_admin_column' => true,                
            'singular_label' => 'Menu',
            'capabilities' => array ( //giving a name to the capability
                'manage_terms' => 'manage_servicecategory', 
                'edit_terms' => 'manage_servicecategory',
                'delete_terms' => 'manage_servicecategory',
                'assign_terms' => 'manage_servicecategory'
            )
    ) 
); 
$role = get_role('administrator');
$role->add_cap("manage_servicecategory");
于 2013-09-23T19:14:43.860 回答
1

未经测试,但试试这个添加这个只显示给管理员

'show_ui' => current_user_can( 'update_core' )

这将 ui 限制为仅具有更新 wordpress 功能的用户,这些用户始终是管理员。

于 2016-02-18T13:46:33.923 回答