Opened 12 years ago
Closed 12 years ago
#17215 closed defect (bug) (duplicate)
Featured images for post types without editor can't be used by other types
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.1.1 |
Component: | Post Thumbnails | Keywords: | |
Focuses: | Cc: |
Description
If a featured image is added to a custom post type without the editor enabled, it shows up in the media library and other post types can use it as a featured image, but it can't be added to the post. The "Insert into Post" button is missing when you browse to the image to add it.
I ran into this problem with my own plugin Meteor Slides, but the issue isn't specific to my plugin, it can be reproduced with any custom post type.
I used the example in the Codex to test it, and the problem was the same as with my plugin. I tested this with both 3.1.1 and the nightly of 3.2 and the issue was consistent in both versions.
Change History (2)
Note: See
TracTickets for help on using
tickets.
I ran into exactly the same problem that jleuze describes.
The actual code instance of it appears to come from the default $args set in the get_media_item() function in wp-admin/includes/media.php. The appearance of the button is controlled by the 'send' part of $args and that is set to positive if the attachment is attached to a post type which supports the 'editor'. This appears in the get_media_item function as
'send' => $post->post_parent ? post_type_supports( get_post_type( $post->post_parent ), 'editor' ) : true
That assumes that an attached image will only ever be inserted into a post with the same post-type as its parent. A better check would be to test whether the post type of the currently edited post supports the 'editor'. For example:
'send' => $_REQUEST['post_id'] ? post_type_supports( get_post_type( $_REQUEST['post_id'] ), 'editor' ) : false
That is - if the currently edited post is identified and that identified post supports the editor then show the insert button otherwise there is nowhere to send the image so default to not showing the button.
A plug-in level work around would be to use the 'get_media_item_args' filter.