我正在使用Members插件管理自定义角色的功能,该角色只能编辑/发布我在函数中创建的自定义帖子类型。php文件。在做了很多工作之后,我实现了这一点,除了预览按钮不起作用,而且(更糟糕的是)阻止保存/发布自定义帖子。
只要我不点击预览按钮,一切都正常。但当我单击预览按钮时,预览选项卡不会显示自上次保存以来所做的任何更改。然后,当我按“发布/更新”按钮时,我的更改不会保存/发布,而是加载到“预览”选项卡中,就像我按了“预览”一样。在我使用WordPress编辑帖子的浏览器选项卡中,没有其他任何事情发生,更新/发布按钮旁边的微调器一直在旋转。
从我的管理员帐户中,一切都很正常,如果我给自定义角色“edit\\u posts”功能,就可以解决这个问题。因此,这个角色的自定义功能似乎出了问题,但我无法理解。
下面是我的函数代码。php。谢谢你的建议。
// Register Custom Post Type
function mnp_custom_post_type() {
$labels = array(
\'name\' => \'Wiki Pages\',
\'singular_name\' => \'Wiki Page\',
\'menu_name\' => \'Wiki Pages\',
\'parent_item_colon\' => \'Parent Wiki Page:\',
\'all_items\' => \'All Wiki Pages\',
\'view_item\' => \'View Wiki Page\',
\'add_new_item\' => \'Add New Wiki Page\',
\'add_new\' => \'New Wiki Page\',
\'edit_item\' => \'Edit Wiki Page\',
\'update_item\' => \'Update Wiki Page\',
\'search_items\' => \'Search wiki pages\',
\'not_found\' => \'No wiki pages found\',
\'not_found_in_trash\' => \'No wiki pages found in Trash\',
);
$rewrite = array(
\'slug\' => \'wiki\',
\'with_front\' => false,
\'pages\' => true,
\'feeds\' => true,
);
$capabilities = array(
\'edit_post\' => \'edit_wiki_page\',
\'read_post\' => \'read_wiki_page\',
\'delete_post\' => \'delete_wiki_page\',
\'edit_posts\' => \'edit_wiki_pages\',
\'edit_others_posts\' => \'edit_others_wiki_pages\',
\'publish_posts\' => \'publish_wiki_pages\',
\'read_private_posts\' => \'read_private_wiki_pages\',
\'delete_posts\' => \'delete_wiki_pages\',
\'delete_private_posts\' => \'delete_private_wiki_pages\',
\'delete_published_posts\' => \'delete_published_wiki_pages\',
\'delete_others_posts\' => \'delete_others_wiki_pages\',
\'edit_private_posts\' => \'edit_private_wiki_pages\',
\'edit_published_posts\' => \'edit_published_wiki_pages\',
);
$args = array(
\'label\' => \'wiki_page\',
\'description\' => \'Wiki pages\',
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'revisions\', ),
\'taxonomies\' => array( \'category\', \'post_tag\' ),
\'hierarchical\' => false,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'show_in_nav_menus\' => true,
\'show_in_admin_bar\' => true,
\'menu_position\' => 25,
\'menu_icon\' => \'\',
\'can_export\' => true,
\'has_archive\' => true,
\'exclude_from_search\' => false,
\'publicly_queryable\' => true,
\'rewrite\' => $rewrite,
\'capabilities\' => $capabilities,
);
register_post_type( \'wiki_page\', $args );
}
// Hook into the \'init\' action
add_action( \'init\', \'mnp_custom_post_type\', 0 );
// map meta capabilities
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 wiki_page, get the post and post type object. */
if ( \'edit_wiki_page\' == $cap || \'delete_wiki_page\' == $cap || \'read_wiki_page\' == $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 wiki_page, assign the required capability. */
if ( \'edit_wiki_page\' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->edit_posts;
else
$caps[] = $post_type->cap->edit_others_posts;
}
/* If deleting a wiki_page, assign the required capability. */
elseif ( \'delete_wiki_page\' == $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 wiki_page, assign the required capability. */
elseif ( \'read_wiki_page\' == $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;
}