[wp-trac] [WordPress Trac] #15779: Can't add featured images to custom post types
WordPress Trac
wp-trac at lists.automattic.com
Sun Dec 12 03:13:00 UTC 2010
#15779: Can't add featured images to custom post types
-----------------------------+----------------------------------------------
Reporter: somatic | Owner: nacin
Type: defect (bug) | Status: reviewing
Priority: normal | Milestone: 3.1
Component: Post Thumbnails | Version: 3.1
Severity: critical | Keywords: reporter-feedback
-----------------------------+----------------------------------------------
Comment(by somatic):
post type register:
{{{
$labels = array(
'name' => _x('Videos', 'post type general name'),
'singular_name' => _x('Video', 'post type singular name'),
'add_new' => _x('Add New', 'Video'),
'add_new_item' => __('Add New Video'),
'edit_item' => __('Edit Video'),
'edit' => _x('Edit', 'video'),
'new_item' => __('New Video'),
'view_item' => __('View Video'),
'search_items' => __('Search Videos'),
'not_found' => __('No Videos found'),
'not_found_in_trash' => __('No Videos found in Trash'),
'view' => __('View Video')
);
$args = array(
'public' => true,
'publicly_queryable' => true,
'menu_icon' => SMAM_IMG .'/videos-menu-icon.png',
'show_ui' => true,
'capability_type' => 'video',
'capabilities' => array(
'publish_posts' => 'publish_videos',
'edit_posts' => 'edit_videos',
'edit_others_posts' => 'edit_others_videos',
'delete_posts' => 'delete_videos',
'delete_others_posts' => 'delete_others_videos',
'read_private_posts' => 'read_private_videos',
'edit_post' => 'edit_video',
'delete_post' => 'delete_video',
'read_post' => 'read_video',
),
'has_archive' => 'videos',
'hierarchical' => true,
'query_var' => true,
'menu_position' => 6,
'show_in_nav_menus' => true,
'supports' => array('thumbnail','comments'),
'rewrite' => array( 'slug' => 'videos', 'with_front' => false ),
'register_meta_box_cb' =>
array('smamMetaboxes','add_custom_boxes'),type
'labels' => $labels
);
register_post_type('videos', $args);
}}}
and function used with add_filter('map_meta_cap'):
{{{
function smam_map_meta_cap( $caps, $cap, $user_id, $args ) {
/* If editing, deleting, or reading an asset, get the post and
post type object. */
if ( 'edit_video' == $cap || 'delete_video' == $cap ||
'read_video' == $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 an item, assign the required capability. */
if ( 'edit_video' == $cap ) {
if ( $user_id == $post->post_author )
$caps[] = $post_type->cap->edit_posts;
else
$caps[] = $post_type->cap->edit_others_posts;
}
/* If deleting an item, assign the required capability. */
elseif ('delete_video' == $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 item, assign the required capability. */
elseif ( 'read_video' == $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;
}
}}}
--
Ticket URL: <http://core.trac.wordpress.org/ticket/15779#comment:3>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software
More information about the wp-trac
mailing list