我正在尝试根据自定义帖子类型功能定义新的用户角色。除了其他功能,我希望这个角色只是删除自己的帖子,而不是其他用户的帖子。
为了实现这一点,我将其定义delete_others_posts(delete_others_dictionary_entry)
为false
但不知何故它不起作用,并且每个具有这个新角色的用户都能够删除所有其他用户的帖子。
add_action('init', 'setup_dictionary_post');
//Register custom post type
function setup_dictionary_post() {
$capabilities = array(
'publish_posts' => 'publish_dictionary_entry',
'edit_posts' => 'edit_dictionary_entry',
'edit_others_posts' => 'edit_others_dictionary_entry',
'delete_posts' => 'delete_dictionary_entry',
'delete_others_posts' => 'delete_others_dictionary_entry',
'read_private_posts' => 'read_private_dictionary_entry'
);
$labels = array(
'name' => 'Dictionary Entries',
'singular_name' => 'Dictionary Entry',
'menu_name' => 'Dictionary Entries',
'add_new' => 'Add New',
'add_new_item' => 'Add New Dictionary Entry',
'edit' => 'Edit entry',
'edit_item' => 'Edit Dictionary Entry',
'new_item' => 'New Dictionary Entry',
'view' => 'View Dictionary Entry',
'view_item' => 'View Dictionary Entry',
'search_items' => 'Search Dictionary Entries',
'not_found' => 'No Dictionary Entries Found',
'not_found_in_trash' => 'No Dictionary Entries Found in Trash',
'parent' => 'Parent Dictionary Entry');
register_post_type('dictionary_entry',
array(
'label' => 'Dictionary Entries',
'description' => '',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'dictionary_entry',
'capabilities'=>$capabilities,
'hierarchical' => false,
'rewrite' => array('slug' => ''),
'query_var' => true,
'supports' => array('title','comments','revisions','thumbnail','author','page-attributes',),
'labels' => $labels,
)
);
flush_rewrite_rules(false);
/********************** CUSTOM ROLE *****************************/
remove_role('dictionary_entry_author');
add_role('dictionary_entry_author',
'Dictionary Helper', array(
'publish_dictionary_entry' => true,
'edit_dictionary_entry' => true,
'edit_others_dictionary_entry' => true,
'delete_dictionary_entry' => true,
'delete_others_dictionary_entry' => false,
'read_private_dictionary_entry' => true,
'read_dictionary_entry' => true,
'read' => true
));
}