From 75d4429926bfcd5667965f704169d01747e0a89c Mon Sep 17 00:00:00 2001 From: Dominik Schilling Date: Mon, 15 Aug 2016 19:16:31 +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]. Props flixos90, joemcgill, DrewAPicture, wonderboymusic. See #12922. Fixes #37658. Built from https://develop.svn.wordpress.org/trunk@38263 git-svn-id: http://core.svn.wordpress.org/trunk@38204 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 e0cd82c003..5820771845 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.7-alpha-38261'; +$wp_version = '4.7-alpha-38263'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.