Make WordPress Core

Changeset 38433


Ignore:
Timestamp:
08/29/2016 12:24:09 PM (10 years ago)
Author:
joemcgill
Message:

Post Thumbnails: Prevent post thumbnail previews from spilling into other images.

After [38118], when previewing a page with a secondary loop, all post
thumbnails would be filtered to display the post thumbnail for the
page being previewed. This ensures _wp_preview_post_thumbnail_filter()
is only applied if the $post_id of the post meta being filtered is
equal to the post or page being previewed.

Props swisspidy, joemcgill.
Fixes #37697.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/revision.php

    r38118 r38433  
    595595        }
    596596
    597         if ( empty( $_REQUEST['_thumbnail_id'] ) || $post->ID != $post_id || '_thumbnail_id' != $meta_key || 'revision' == $post->post_type ) {
     597        if ( empty( $_REQUEST['_thumbnail_id'] ) ||
     598             empty( $_REQUEST['preview_id'] ) ||
     599             $post->ID != $post_id ||
     600             '_thumbnail_id' != $meta_key ||
     601             'revision' == $post->post_type ||
     602             $post_id != $_REQUEST['preview_id']
     603        ) {
    598604                return $value;
    599605        }
  • trunk/tests/phpunit/tests/post/thumbnails.php

    r38398 r38433  
    238238                $GLOBALS['post'] = self::$post;
    239239                $_REQUEST['_thumbnail_id'] = self::$attachment_id;
     240                $_REQUEST['preview_id'] = self::$post->ID;
    240241
    241242                $result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
     243
     244                // Clean up.
     245                $GLOBALS['post'] = $old_post;
     246                unset( $_REQUEST['_thumbnail_id'] );
     247                unset( $_REQUEST['preview_id'] );
     248
    242249                $this->assertEquals( self::$attachment_id, $result );
    243 
     250        }
     251
     252        /**
     253         * @ticket 37697
     254         */
     255        function test__wp_preview_post_thumbnail_filter_secondary_post() {
     256                $old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
     257
     258                $secondary_post = self::factory()->post->create( array(
     259                                'post_stauts' => 'publish',
     260                        )
     261                );
     262
     263                $GLOBALS['post'] = self::$post;
     264                $_REQUEST['_thumbnail_id'] = self::$attachment_id;
     265                $_REQUEST['preview_id'] = $secondary_post;
     266
     267                $result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
     268
     269                // Clean up.
     270                $GLOBALS['post'] = $old_post;
    244271                unset( $_REQUEST['_thumbnail_id'] );
    245                 if ( null === $old_post ) {
    246                         unset( $GLOBALS['post'] );
    247                 } else {
    248                         $GLOBALS['post'] = $old_post;
    249                 }
     272                unset( $_REQUEST['preview_id'] );
     273
     274                $this->assertEmpty( $result );
    250275        }
    251276
Note: See TracChangeset for help on using the changeset viewer.