1

我只是在学习 Wordpress 的自定义分类法。如何限制我的用户使用分类法的访问权限。例如,我创建了一个名为的分类法featured,我只希望编辑及以上角色能够向该分类法添加帖子。

如何设置访问级别?无论是基于用户角色还是能力,都对我有用。

这是我用于分类的代码:

function add_custom_taxonomies() {
    // Add new "Featured" taxonomy to Posts
    register_taxonomy('featured', 'post', array(
        // Hierarchical taxonomy (like categories)
        'hierarchical' => true,
        // This array of options controls the labels displayed in the WordPress Admin UI
        'labels' => array(
            'name' => _x( 'Featured', 'taxonomy general name' ),
            'singular_name' => _x( 'Featured', 'taxonomy singular name' ),
            'search_items' =>  __( 'Search Featured' ),
            'all_items' => __( 'All Featured' ),
            'parent_item' => __( 'Parent Featured' ),
            'parent_item_colon' => __( 'Parent Featured:' ),
            'edit_item' => __( 'Edit Featured' ),
            'update_item' => __( 'Update Featured' ),
            'add_new_item' => __( 'Add New Featured' ),
            'new_item_name' => __( 'New Featured Name' ),
            'menu_name' => __( 'Featured' ),
        ),
        // Control the slugs used for this taxonomy
        'rewrite' => array(
            'slug' => 'featured', // This controls the base slug that will display before each term
            'with_front' => false, // Don't display the category base before "/locations/"
            'hierarchical' => true // This will allow URL's like "/locations/boston/cambridge/"
        ),
    ));
}
add_action( 'init', 'add_custom_taxonomies', 0 );
4

1 回答 1

2

从帖子编辑页面中删除元框就足够了吗?如果是这样,试一试

function remove_featured_meta() {
   if (!current_user_can('moderate_comments')){
       remove_meta_box( 'featureddiv', 'post', 'side' );
   }
}

add_action( 'admin_menu' , 'remove_featured_meta' );

您可以使用与您希望限制对分类的访问权限的用户角色相对应的任何适当能力填写条件语句。

于 2012-09-17T17:39:30.753 回答