php怎么设置访问权限,php – 自定义分类 – 根据角色或功能设置访问权限

我只是在学习Wordpress的自定义分类法.如何限制用户访问分类的访问权限.例如,我创建了一个名为features的分类,我只希望编辑器和上面的角色能够将帖子添加到此分类中.

如何设置访问级别?基于用户角色或能力,两者都适合我.

这是我用于分类的代码:

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

解决方法:

从Post Edit页面中删除元数据是否足够?如果是这样,请给this一个旋转:

function remove_featured_meta() {

if (!current_user_can('moderate_comments')){

remove_meta_box( 'featureddiv', 'post', 'side' );

}

}

add_action( 'admin_menu' , 'remove_featured_meta' );

您可以使用任何appropriate capability对应于您要限制对分类法的访问权限的用户角色来填写条件语句.

标签:taxonomy,php,wordpress,capability,role

来源: https://codeday.me/bug/20191007/1867430.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值