diff --git a/src/wp-includes/revision.php b/src/wp-includes/revision.php index b588621944..07a986c003 100644 --- a/src/wp-includes/revision.php +++ b/src/wp-includes/revision.php @@ -594,7 +594,13 @@ function _wp_preview_post_thumbnail_filter( $value, $post_id, $meta_key ) { return $value; } - if ( empty( $_REQUEST['_thumbnail_id'] ) || $post->ID != $post_id || '_thumbnail_id' != $meta_key || 'revision' == $post->post_type ) { + if ( empty( $_REQUEST['_thumbnail_id'] ) || + empty( $_REQUEST['preview_id'] ) || + $post->ID != $post_id || + '_thumbnail_id' != $meta_key || + 'revision' == $post->post_type || + $post_id != $_REQUEST['preview_id'] + ) { return $value; } diff --git a/tests/phpunit/tests/post/thumbnails.php b/tests/phpunit/tests/post/thumbnails.php index f3ebeeb3d7..cc3c183f55 100644 --- a/tests/phpunit/tests/post/thumbnails.php +++ b/tests/phpunit/tests/post/thumbnails.php @@ -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 ); } /**