Wordpress post 类型 posts 混入后端非管理员角色
Wordpress post types posts mixing in backend non admine roles
我正在从头开始构建一个 wordpress 主题。我有一些经验,但我对我的定制非常细致,所以我在这一点上遇到了一些问题。
问题如下:我创建了一些特殊的 post 类型,它们具有自己的功能并允许一些自定义的新角色访问它们。一切正常,但是当这个新角色 -'writer'- 在后端写入时,我创建的不同 post 类型的 posts 在 post 类型中混淆了仪表板,就在它列出 post 的地方。
所以我们有这些 post 类型:
- 评论
- 预览
评论仪表板同时列出评论和预览 post 由该作者撰写,预览仪表板也是如此。
这不会发生在管理员身上。这就是让我认为这是许可的原因。
这里是 post 类型代码:
// ==================================== //
// R E V I E W S //
// ==================================== //
// Register Custom Post Type
function custom_post_type_reviews() {
$labels = array(
'name' => _x( 'Reviews', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Review', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Reviews', 'text_domain' ),
'name_admin_bar' => __( 'Reviews', 'text_domain' ),
'archives' => __( 'Reviews archive', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All the reviews', 'text_domain' ),
'add_new_item' => __( 'Add new review', 'text_domain' ),
'add_new' => __( 'Add new', 'text_domain' ),
'new_item' => __( 'Add item', 'text_domain' ),
'edit_item' => __( 'Edit item', 'text_domain' ),
'update_item' => __( 'Update item', 'text_domain' ),
'view_item' => __( 'View item', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in trash', 'text_domain' ),
'featured_image' => __( 'Featured image', 'text_domain' ),
'set_featured_image' => __( 'Add featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use featured image', 'text_domain' ),
'insert_into_item' => __( 'insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Update to this item', 'text_domain' ),
'items_list' => __( 'Items lists', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$capabilities = array(
'publish_posts' => 'publish_reviews',
'edit_posts' => 'edit_reviews',
'edit_others_posts' => 'edit_others_reviews',
'delete_posts' => 'delete_reviews',
'delete_others_posts' => 'delete_others_reviews',
'read_private_posts' => 'read_private_reviews',
'edit_post' => 'edit_review',
'delete_post' => 'delete_review',
'read_post' => 'read_review',
);
$args = array(
'label' => __( 'Reviews', 'text_domain' ),
'description' => __( 'Reviews', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author','comments' ),
'taxonomies' => array( 'categories', 'post_tag', ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-media-text',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'map_meta_cap' => true,
'capability_type' => 'review',
'capabilities' => $capabilities,
);
register_post_type( 'reviews', $args );
}
add_action( 'init', 'custom_post_type_reviews', 0 );
为了创建角色,我安装了一个名为 Memebers 的插件,我附上了分配给我创建的 'role' 的功能的图像。
Role capabilities
我不知道这可能是什么,但我不是文字新闻专业人士。
谢谢!!!
我在 map_meta_cap
、capability_type
和 capabilities
的组合中发现了各种潜在的错误,请在 the Codex 中查看所有这些错误。我认为它应该适用于以下情况:
(1)
capability_type
设置为 review
map_meta_cap
设置为 false
- 不需要使用
capabilities
您的角色功能中的角色应该与 the Codex 匹配插件和单数 - 我的意思是 "review" 或 "reviews"。
(2)
capability_type
设置为 review
map_meta_cap
设置为 true
- 使用
capabilities
- 检查 Codex
检查 $capabilites
中的数组是否与角色编辑器中使用的 $capabilities
匹配。
我发现是什么在混合 posts。我就是用这个功能来列出作者 post 即使是作者页面中的自定义作者。
function custom_post_author_archive( &$query )
{
if ( $query->is_author )
$query->set( 'post_type', all_post_types() );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action( 'pre_get_posts', 'custom_post_author_archive' );
我正在从头开始构建一个 wordpress 主题。我有一些经验,但我对我的定制非常细致,所以我在这一点上遇到了一些问题。
问题如下:我创建了一些特殊的 post 类型,它们具有自己的功能并允许一些自定义的新角色访问它们。一切正常,但是当这个新角色 -'writer'- 在后端写入时,我创建的不同 post 类型的 posts 在 post 类型中混淆了仪表板,就在它列出 post 的地方。
所以我们有这些 post 类型: - 评论 - 预览
评论仪表板同时列出评论和预览 post 由该作者撰写,预览仪表板也是如此。
这不会发生在管理员身上。这就是让我认为这是许可的原因。
这里是 post 类型代码:
// ==================================== //
// R E V I E W S //
// ==================================== //
// Register Custom Post Type
function custom_post_type_reviews() {
$labels = array(
'name' => _x( 'Reviews', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Review', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Reviews', 'text_domain' ),
'name_admin_bar' => __( 'Reviews', 'text_domain' ),
'archives' => __( 'Reviews archive', 'text_domain' ),
'parent_item_colon' => __( 'Parent Item:', 'text_domain' ),
'all_items' => __( 'All the reviews', 'text_domain' ),
'add_new_item' => __( 'Add new review', 'text_domain' ),
'add_new' => __( 'Add new', 'text_domain' ),
'new_item' => __( 'Add item', 'text_domain' ),
'edit_item' => __( 'Edit item', 'text_domain' ),
'update_item' => __( 'Update item', 'text_domain' ),
'view_item' => __( 'View item', 'text_domain' ),
'search_items' => __( 'Search Item', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in trash', 'text_domain' ),
'featured_image' => __( 'Featured image', 'text_domain' ),
'set_featured_image' => __( 'Add featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use featured image', 'text_domain' ),
'insert_into_item' => __( 'insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Update to this item', 'text_domain' ),
'items_list' => __( 'Items lists', 'text_domain' ),
'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter items list', 'text_domain' ),
);
$capabilities = array(
'publish_posts' => 'publish_reviews',
'edit_posts' => 'edit_reviews',
'edit_others_posts' => 'edit_others_reviews',
'delete_posts' => 'delete_reviews',
'delete_others_posts' => 'delete_others_reviews',
'read_private_posts' => 'read_private_reviews',
'edit_post' => 'edit_review',
'delete_post' => 'delete_review',
'read_post' => 'read_review',
);
$args = array(
'label' => __( 'Reviews', 'text_domain' ),
'description' => __( 'Reviews', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt', 'author','comments' ),
'taxonomies' => array( 'categories', 'post_tag', ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-media-text',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'map_meta_cap' => true,
'capability_type' => 'review',
'capabilities' => $capabilities,
);
register_post_type( 'reviews', $args );
}
add_action( 'init', 'custom_post_type_reviews', 0 );
为了创建角色,我安装了一个名为 Memebers 的插件,我附上了分配给我创建的 'role' 的功能的图像。 Role capabilities
我不知道这可能是什么,但我不是文字新闻专业人士。
谢谢!!!
我在 map_meta_cap
、capability_type
和 capabilities
的组合中发现了各种潜在的错误,请在 the Codex 中查看所有这些错误。我认为它应该适用于以下情况:
(1)
capability_type
设置为review
map_meta_cap
设置为false
- 不需要使用
capabilities
您的角色功能中的角色应该与 the Codex 匹配插件和单数 - 我的意思是 "review" 或 "reviews"。
(2)
capability_type
设置为review
map_meta_cap
设置为true
- 使用
capabilities
- 检查 Codex
检查 $capabilites
中的数组是否与角色编辑器中使用的 $capabilities
匹配。
我发现是什么在混合 posts。我就是用这个功能来列出作者 post 即使是作者页面中的自定义作者。
function custom_post_author_archive( &$query )
{
if ( $query->is_author )
$query->set( 'post_type', all_post_types() );
remove_action( 'pre_get_posts', 'custom_post_author_archive' );
}
add_action( 'pre_get_posts', 'custom_post_author_archive' );