如果你是一个 wordpress 开发者,给自己的日志(或者自定义类型的日志)添加自定义分类模式(custom taxonomy),并且你的系统还支持注册用户在前台通过一个表单来投稿,并且需要用户也能输入自定义分类,这个时候你就使用 wp_insert_post
函数来插入日志,但是 wp_insert_post
函数内部是有权限判断的:
if ( current_user_can($taxonomy_obj->cap->assign_terms) ) wp_set_post_terms( $post_ID,$tags,$taxonomy );
自定义分类模式(custom taxonomy)默认的 assign_terms
权限是:manage_categories
,可以管理分类,而只有管理员或者编辑(editor)可以管理分类。所以我们在创建自定义分类的时候,就要将其 assign_terms
权限设置为支持订阅者。比如:
register_taxonomy( 'device','post',array( 'hierarchical' => true,'label' => '适用设备','query_var' => true,'rewrite' => array('slug' => 'device','with_front'=>false),'capabilities' => array( 'manage_terms' => 'manage_categories','edit_terms' => 'manage_categories','delete_terms' => 'manage_categories','assign_terms' => 'read' ) ));