diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index 887f31ad28..8dc481508f 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -24,9 +24,16 @@ $post_ID = isset($post_ID) ? (int) $post_ID : 0; $user_ID = isset($user_ID) ? (int) $user_ID : 0; $action = isset($action) ? $action : ''; -$media_support = theme_supports_thumbnails( $post ) || post_supports_thumbnails( $post ); +$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ); +if ( ! $thumbnail_support && 'attachment' === $post_type && $post->post_mime_type ) { + if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) { + $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' ); + } elseif ( 0 === strpos( $post->post_mime_type, 'video/' ) ) { + $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); + } +} -if ( post_type_supports( $post_type, 'editor' ) || post_type_supports( $post_type, 'thumbnail' ) || $media_support ) { +if ( $thumbnail_support ) { add_thickbox(); wp_enqueue_media( array( 'post' => $post_ID ) ); } @@ -169,7 +176,7 @@ foreach ( get_object_taxonomies( $post ) as $tax_name ) { if ( post_type_supports($post_type, 'page-attributes') ) add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); -if ( current_theme_supports( 'post-thumbnails', $post_type ) || post_supports_thumbnails( $post ) ) +if ( $thumbnail_support ) add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); if ( post_type_supports($post_type, 'excerpt') ) diff --git a/wp-includes/media.php b/wp-includes/media.php index 7feccd00c3..a92873062d 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -2452,7 +2452,16 @@ function wp_enqueue_media( $args = array() ) { 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), ); - if ( theme_supports_thumbnails( $post ) || post_supports_thumbnails( $post ) ) { + $thumbnail_support = current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ); + if ( ! $thumbnail_support && 'attachment' === $post->post_type && $post->post_mime_type ) { + if ( 0 === strpos( $post->post_mime_type, 'audio/' ) ) { + $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' ); + } elseif ( 0 === strpos( $post->post_mime_type, 'video/' ) ) { + $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' ); + } + } + + if ( $thumbnail_support ) { $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true ); $settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1; } @@ -2756,45 +2765,3 @@ function wp_maybe_generate_attachment_metadata( $attachment ) { } } } - -/** - * Determine if a post supports thumbnails based on the passed post object. - * - * @since 3.9.0 - * - * @param WP_Post $post Post object. - * - * @return bool Whether the post type supports thumbnails. - */ -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 object. - * - * @since 3.9.0 - * - * @param WP_Post $post Post object. - * - * @return bool Whether the current theme supports thumbnails. - */ -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 ); -}