Make WordPress Core

Ticket #37658: 37658.2.diff

File 37658.2.diff, 3.8 KB (added by flixos90, 10 years ago)
  • src/wp-includes/post.php

     
    32603260        }
    32613261
    32623262        // Set or remove featured image.
    3263         if ( isset( $postarr['_thumbnail_id'] ) && ( post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type ) ) {
    3264                 $thumbnail_id = intval( $postarr['_thumbnail_id'] );
    3265                 if ( -1 === $thumbnail_id ) {
    3266                         delete_post_thumbnail( $post_ID );
    3267                 } else {
    3268                         set_post_thumbnail( $post_ID, $thumbnail_id );
     3263        if ( isset( $postarr['_thumbnail_id'] ) ) {
     3264                $thumbnail_support = post_type_supports( $post_type, 'thumbnail' ) || 'revision' === $post_type;
     3265                if ( ! $thumbnail_support && 'attachment' === $post_type && $post_mime_type ) {
     3266                        if ( wp_attachment_is( 'audio', $post_ID ) ) {
     3267                                $thumbnail_support = post_type_supports( 'attachment:audio', 'thumbnail' );
     3268                        } elseif ( wp_attachment_is( 'video', $post_ID ) ) {
     3269                                $thumbnail_support = post_type_supports( 'attachment:video', 'thumbnail' );
     3270                        }
    32693271                }
     3272
     3273                if ( $thumbnail_support ) {
     3274                        $thumbnail_id = intval( $postarr['_thumbnail_id'] );
     3275                        if ( -1 === $thumbnail_id ) {
     3276                                delete_post_thumbnail( $post_ID );
     3277                        } else {
     3278                                set_post_thumbnail( $post_ID, $thumbnail_id );
     3279                        }
     3280                }
    32703281        }
    32713282
    32723283        if ( ! empty( $postarr['meta_input'] ) ) {
  • tests/phpunit/tests/post/thumbnails.php

     
    233233
    234234                $this->assertEquals( wp_get_attachment_url( self::$attachment_id ), $actual );
    235235        }
     236
     237        /**
     238         * @ticket 12922
     239         */
     240        function test__wp_preview_post_thumbnail_filter() {
     241                $post_id = self::factory()->post->create();
     242
     243                $_REQUEST['_thumbnail_id'] = self::$attachment_id;
     244
     245                $result = _wp_preview_post_thumbnail_filter( '', $post_id, '_thumbnail_id' );
     246                $this->assertEquals( self::$attachment_id, $result );
     247        }
     248
     249        /**
     250         * @ticket 12922
     251         */
     252        function test_insert_post_with_post_thumbnail() {
     253                $post_id = wp_insert_post( array(
     254                        'post_status' => 'publish',
     255                        'post_content' => rand_str(),
     256                        'post_title' => rand_str(),
     257                        '_thumbnail_id' => self::$attachment_id,
     258                ) );
     259
     260                $thumbnail_id = get_post_thumbnail_id( $post_id );
     261                $this->assertEquals( self::$attachment_id, $thumbnail_id );
     262
     263                $post_id = wp_insert_post( array(
     264                        'ID' => $post_id,
     265                        'post_status' => 'publish',
     266                        'post_content' => rand_str(),
     267                        'post_title' => rand_str(),
     268                        '_thumbnail_id' => -1, // -1 removes post thumbnail.
     269                ) );
     270
     271                $thumbnail_id = get_post_thumbnail_id( $post_id );
     272                $this->assertEmpty( $thumbnail_id );
     273        }
     274
     275        /**
     276         * @ticket 37658
     277         */
     278        function test_insert_attachment_with_post_thumbnail() {
     279                // Audio files support featured images.
     280                $post_id = wp_insert_post( array(
     281                        'post_type' => 'attachment',
     282                        'post_status' => 'publish',
     283                        'post_content' => rand_str(),
     284                        'post_title' => rand_str(),
     285                        'post_mime_type' => 'audio/mpeg',
     286                        'post_parent' => 0,
     287                        'file' => DIR_TESTDATA . '/images/canola.jpg',
     288                        '_thumbnail_id' => self::$attachment_id,
     289                ) );
     290
     291                $thumbnail_id = get_post_thumbnail_id( $post_id );
     292                $this->assertEquals( self::$attachment_id, $thumbnail_id );
     293
     294                // Images do not support featured images.
     295                $post_id = wp_insert_post( array(
     296                        'post_type' => 'attachment',
     297                        'post_status' => 'publish',
     298                        'post_content' => rand_str(),
     299                        'post_title' => rand_str(),
     300                        'post_mime_type' => 'image/jpeg',
     301                        'post_parent' => 0,
     302                        'file' => DIR_TESTDATA . '/images/canola.jpg',
     303                        '_thumbnail_id' => self::$attachment_id,
     304                ) );
     305
     306                $thumbnail_id = get_post_thumbnail_id( $post_id );
     307                $this->assertEmpty( $thumbnail_id );
     308        }
    236309}