From 329a17f59a2f0e810962263f1a694e6cad17f0f0 Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 15 Aug 2016 19:18:30 +0000 Subject: [PATCH] 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 --- wp-includes/post.php | 31 +++++++++++++++++++++---------- wp-includes/version.php | 2 +- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/wp-includes/post.php b/wp-includes/post.php index 9bc645f4d4..d033172763 100644 --- a/wp-includes/post.php +++ b/wp-includes/post.php @@ -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 ); diff --git a/wp-includes/version.php b/wp-includes/version.php index 5922830788..763a4bb903 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.