[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 01:55:59 UTC 2010


#15779: Can't add featured images to custom post types
-----------------------------+----------------------------------------------
 Reporter:  somatic          |       Owner:                 
     Type:  defect (bug)     |      Status:  new            
 Priority:  normal           |   Milestone:  Awaiting Review
Component:  Post Thumbnails  |     Version:  3.1            
 Severity:  critical         |    Keywords:                 
-----------------------------+----------------------------------------------
 In all the 3.1 beta builds, up to 3.1-beta1-16723, whenever I try to add a
 featured image to a custom post type item, through the media uploader
 thickbox, clicking "use as featured image", the Featured Image metabox
 content shows "-1", and no image.

 This is with a custom post type whose 'capability_type' is set to a custom
 value (not "post").

 I've tracked the "-1" output down to wp-admin/admin-ajax.php, line 1425

 {{{
 if ( !current_user_can( 'edit_post', $post_ID ) )
         die( '-1' );
 }}}

 This code seems unchanged from WP 3.0 - 3.0.3, where I didn't have this
 problem. I'm assuming something has changed in 3.1 with regards to
 map_meta_cap or other custom post type capability checking.

 AFAIK, the conditional is failing because the $post_ID being checked isn't
 "post" type, and so the capability "edit_post" doesn't apply.

 If I manually change "edit_post" to "edit_mycustomtype", the test works,
 and the featured image thumbnail shows up in the proper metabox.

 I don't know that this is a proper solution, as a custom post type's
 capability type could technically be set to ''anything'', but this fix at
 least checks the capability against the post type's name (which is how I
 usually do it):

 {{{
 $post_type = get_post_type( $post_ID );
 if ( !current_user_can( 'edit_' . $post_type, $post_ID ) )
 die( '-1' );
 }}}

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/15779>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list