Bad preview button glitch with custom role/post type/capabilities
-
I’ve created a custom post type, and a custom role to go with it. Those with this role will only be able to edit the custom posts.
I’ve got this pretty much working by coding the custom post type in functions.php and then using the Members plugin to create the new role and assign it just the capabilities to edit the custom posts.
I am getting some very strange behavior with the preview button though. I log in with the custom role, and I can create, open, and edit posts. If I do not click the preview button I can publish my edits to the post (or publish a new post). However (and here’s where it gets weird) if I click the preview button a tab opens with a preview that does not show any of the changes I’ve made since the last save. Then when I press the publish or update button, my changes are not saved or published, but are loaded into the “preview” browser tab. Nothing else happens in the browser tab where I’m using WordPress to edit the post, the spinny spinner just keeps spinning.
Everything works fine from my admin account, so it looks like something is amiss in the custom role / capabilities dept rather than with the custom post type.
Anyone run into this before? Any ideas on how to fix it? My code from functions.php is below.
Thanks,
-Paul// 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’, ‘author’, ‘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 movie, 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 movie, 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 movie, 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 movie, 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;
}
- The topic ‘Bad preview button glitch with custom role/post type/capabilities’ is closed to new replies.