Allow pseudo post types `attachment:audio` and `attachment:video` to get the media modal on Edit Media when they support featured images.

Introduces `post_supports_thumbnails( $post )` and `theme_supports_thumbnails( $post )` to cut down on duplicated code everytime this needs to be checked. There will be more cases forthcoming.

See #26631.


Built from https://develop.svn.wordpress.org/trunk@27209


git-svn-id: http://core.svn.wordpress.org/trunk@27066 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Scott Taylor 2014-02-20 17:50:13 +00:00
parent 0469b382a3
commit 7ff83d46aa
2 changed files with 52 additions and 2 deletions

View File

@ -24,7 +24,13 @@ $post_ID = isset($post_ID) ? (int) $post_ID : 0;
$user_ID = isset($user_ID) ? (int) $user_ID : 0;
$action = isset($action) ? $action : '';
if ( post_type_supports($post_type, 'editor') || post_type_supports($post_type, 'thumbnail') ) {
$media_type = false;
if ( 'attachment' && $post_ID ) {
$post = get_post( $post_ID );
$media_type = post_supports_thumbnails( $post );
}
if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'thumbnail' ) || $media_type ) {
add_thickbox();
wp_enqueue_media( array( 'post' => $post_ID ) );
}

View File

@ -2012,7 +2012,7 @@ function wp_enqueue_media( $args = array() ) {
'nonce' => wp_create_nonce( 'update-post_' . $post->ID ),
);
if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) {
if ( theme_supports_thumbnails( $post ) && post_supports_thumbnails( $post ) ) {
$featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
}
@ -2240,6 +2240,8 @@ function get_post_gallery_images( $post = 0 ) {
/**
* If an attachment is missing its metadata, try to regenerate it
*
* @since 3.9.0
*
* @param post $attachment Post object.
*/
function maybe_regenerate_attachment_metadata( $attachment ) {
@ -2259,3 +2261,45 @@ function maybe_regenerate_attachment_metadata( $attachment ) {
}
}
}
/**
* Determine if a post supports thumbnails based on the passed $post
*
* @since 3.9.0
*
* @param WP_Post $post
*
* @return boolean
*/
function post_supports_thumbnails( $post ) {
if ( 'attachment' === $post->post_type ) {
if ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
return post_type_supports( 'attachment:audio', 'thumbnail' );
} elseif ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
return post_type_supports( 'attachment:video', 'thumbnail' );
}
}
return post_type_supports( $post->post_type, 'thumbnail' );
}
/**
* Determine if a theme supports thumbnails based on the passed $post
*
* @since 3.9.0
*
* @param WP_Post $post
*
* @return boolean
*/
function theme_supports_thumbnails( $post ) {
if ( 'attachment' === $post->post_type ) {
if ( 0 === strpos( $post->post_mime_type, 'audio' ) ) {
return current_theme_supports( 'post-thumbnails', 'attachment:audio' );
} elseif ( 0 === strpos( $post->post_mime_type, 'video' ) ) {
return current_theme_supports( 'post-thumbnails', 'attachment:video' );
}
}
return current_theme_supports( 'post-thumbnails', $post->post_type );
}