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. git-svn-id: https://develop.svn.wordpress.org/trunk@27209 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3776fd7d5d
commit
ae603ef26d
@ -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 ) );
|
||||
}
|
||||
|
@ -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 );
|
||||
}
|
Loading…
Reference in New Issue
Block a user