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.