我希望用户组“订阅者”中的用户授予写入(自定义帖子类型)“指南”的权限。我下载了成员插件并提供了edit_guides,delete_guide权限。我的Function.php目前是:
add_action('init', 'cptui_register_my_cpt_guides');
function cptui_register_my_cpt_guides() {
register_post_type('guides', array(
'label' => 'Guides',
'description' => 'League of Legends Player Guides',
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'capability_type' => 'guides',
'map_meta_cap' => true,
'hierarchical' => false,
'rewrite' => array('slug' => 'guides', 'with_front' => true),
'query_var' => true,
'has_archive' => true,
'supports' => array('title','editor','excerpt','trackbacks','custom-fields','comments','revisions','thumbnail','author','page-attributes','post-formats'),
'labels' => array (
'name' => 'Guides',
'singular_name' => 'guides',
'menu_name' => 'Guides',
'add_new' => 'Add guides',
'add_new_item' => 'Add New guides',
'edit' => 'Edit',
'edit_item' => 'Edit guides',
'new_item' => 'New guides',
'view' => 'View guides',
'view_item' => 'View guides',
'search_items' => 'Search Guides',
'not_found' => 'No Guides Found',
'not_found_in_trash' => 'No Guides Found in Trash',
'parent' => 'Parent guides',
)
) ); }
和
add_filter( 'map_meta_cap', 'my_map_meta_cap', 10, 4 );
function my_map_meta_cap( $caps, $cap, $user_id, $args ) {
/* If editing, deleting, or reading a guides, get the post and post type object. */
if ( 'edit_guides' == $cap || 'delete_guides' == $cap || 'read_guides' == $cap ) {
$post = get_post( $args[0] );
$post_type = get_post_type_object( $post->post_type );
/* Set an empty array for the caps. */
$caps = array();
}
/* If editing a guides, assign the required capability. */
if ( 'edit_guides' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->edit_posts;
else
$caps[] = $post_type->cap->edit_others_posts;
}
/* If deleting a guides, assign the required capability. */
elseif ( 'delete_guides' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->delete_posts;
else
$caps[] = $post_type->cap->delete_others_posts;
}
/* If reading a private guides, assign the required capability. */
elseif ( 'read_guides' == $cap ) {
if ( 'private' != $post->post_status )
$caps[] = 'read';
elseif ( $user_id == $post->post_author )
$caps[] = 'read';
else
$caps[] = $post_type->cap->read_private_posts;
}
/* Return the capabilities required by the user. */
return $caps;
}
如果我的能力类型= post,那么一切正常。但每当我改变它时,指南就会从wp-admin中消失。提前谢谢。