mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
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. git-svn-id: https://develop.svn.wordpress.org/trunk@38433 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -237,16 +237,41 @@ class Tests_Post_Thumbnail_Template extends WP_UnitTestCase {
|
||||
|
||||
$GLOBALS['post'] = self::$post;
|
||||
$_REQUEST['_thumbnail_id'] = self::$attachment_id;
|
||||
$_REQUEST['preview_id'] = self::$post->ID;
|
||||
|
||||
$result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
|
||||
$this->assertEquals( self::$attachment_id, $result );
|
||||
|
||||
// Clean up.
|
||||
$GLOBALS['post'] = $old_post;
|
||||
unset( $_REQUEST['_thumbnail_id'] );
|
||||
if ( null === $old_post ) {
|
||||
unset( $GLOBALS['post'] );
|
||||
} else {
|
||||
$GLOBALS['post'] = $old_post;
|
||||
}
|
||||
unset( $_REQUEST['preview_id'] );
|
||||
|
||||
$this->assertEquals( self::$attachment_id, $result );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 37697
|
||||
*/
|
||||
function test__wp_preview_post_thumbnail_filter_secondary_post() {
|
||||
$old_post = isset( $GLOBALS['post'] ) ? $GLOBALS['post'] : null;
|
||||
|
||||
$secondary_post = self::factory()->post->create( array(
|
||||
'post_stauts' => 'publish',
|
||||
)
|
||||
);
|
||||
|
||||
$GLOBALS['post'] = self::$post;
|
||||
$_REQUEST['_thumbnail_id'] = self::$attachment_id;
|
||||
$_REQUEST['preview_id'] = $secondary_post;
|
||||
|
||||
$result = _wp_preview_post_thumbnail_filter( '', self::$post->ID, '_thumbnail_id' );
|
||||
|
||||
// Clean up.
|
||||
$GLOBALS['post'] = $old_post;
|
||||
unset( $_REQUEST['_thumbnail_id'] );
|
||||
unset( $_REQUEST['preview_id'] );
|
||||
|
||||
$this->assertEmpty( $result );
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user