Post Thumbnails: Restore thumbnail support for media files.

* Allow to add/remove a featured image to `attachment:audio` and `attachment:video` post types, see [27657].
* Change conditionals to check for theme OR post type support.
* Add tests for #12922.

Broken in [37658].

Merge of [38263] to the 4.6 branch.

Props flixos90, joemcgill, DrewAPicture, wonderboymusic.
See #12922.
See #37658.
Built from https://develop.svn.wordpress.org/branches/4.6@38264


git-svn-id: http://core.svn.wordpress.org/branches/4.6@38205 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Dominik Schilling 2016-08-15 19:18:30 +00:00
parent 58e1032e13
commit 329a17f59a
2 changed files with 22 additions and 11 deletions

View File

@ -3259,16 +3259,6 @@ function wp_insert_post( $postarr, $wp_error = false ) {
}
}
// Set or remove featured image.
if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) {
$thumbnail_id = intval( $postarr['_thumbnail_id'] );
if ( -1 === $thumbnail_id ) {
delete_post_thumbnail( $post_ID );
} else {
set_post_thumbnail( $post_ID, $thumbnail_id );
}
}
if ( ! empty( $postarr['meta_input'] ) ) {
foreach ( $postarr['meta_input'] as $field => $value ) {
update_post_meta( $post_ID, $field, $value );
@ -3292,6 +3282,27 @@ function wp_insert_post( $postarr, $wp_error = false ) {
}
}
// Set or remove featured image.
if ( isset( $postarr['_thumbnail_id'] ) ) {
$thumbnail_support = current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
if ( wp_attachment_is( 'audio', $post_ID ) ) {
$thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:audio' );
} elseif ( wp_attachment_is( 'video', $post_ID ) ) {
$thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' ) || current_theme_supports( 'post-thumbnails', 'attachment:video' );
}
}
if ( $thumbnail_support ) {
$thumbnail_id = intval( $postarr['_thumbnail_id'] );
if ( -1 === $thumbnail_id ) {
delete_post_thumbnail( $post_ID );
} else {
set_post_thumbnail( $post_ID, $thumbnail_id );
}
}
}
clean_post_cache( $post_ID );
$post = get_post( $post_ID );

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.6-RC3-38262';
$wp_version = '4.6-RC3-38264';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.