ユーザーグループ「サブスクライバー」のユーザーに、(カスタム投稿タイプ)「ガイド」を書く許可を与えてもらいたいです。メンバー プラグインをダウンロードし、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;
}
機能タイプ = 投稿の場合、すべてが機能します。しかし、変更するたびに、ガイドが wp-admin から消えてしまいます。前もって感謝します。