From ac85963ad44a889c69faa5ba61597cdc96dc7e30 Mon Sep 17 00:00:00 2001 From: John Blackbourn Date: Mon, 28 Sep 2015 19:25:05 +0000 Subject: [PATCH] Correctly slash post fields when trashing and untrashing posts. Fixes #27550 Props dmenard, Denis-de-Bernardy git-svn-id: https://develop.svn.wordpress.org/trunk@34668 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/post-functions.php | 4 ++-- tests/phpunit/tests/post/slashes.php | 29 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/wp-includes/post-functions.php b/src/wp-includes/post-functions.php index 47db1dfcec..cbe464f967 100644 --- a/src/wp-includes/post-functions.php +++ b/src/wp-includes/post-functions.php @@ -2518,7 +2518,7 @@ function wp_trash_post( $post_id = 0 ) { add_post_meta($post_id,'_wp_trash_meta_time', time()); $post['post_status'] = 'trash'; - wp_insert_post($post); + wp_insert_post( wp_slash( $post ) ); wp_trash_post_comments($post_id); @@ -2565,7 +2565,7 @@ function wp_untrash_post( $post_id = 0 ) { delete_post_meta($post_id, '_wp_trash_meta_status'); delete_post_meta($post_id, '_wp_trash_meta_time'); - wp_insert_post($post); + wp_insert_post( wp_slash( $post ) ); wp_untrash_post_comments($post_id); diff --git a/tests/phpunit/tests/post/slashes.php b/tests/phpunit/tests/post/slashes.php index 4a9f8be3ad..ee93abb7ad 100644 --- a/tests/phpunit/tests/post/slashes.php +++ b/tests/phpunit/tests/post/slashes.php @@ -129,4 +129,33 @@ class Tests_Post_Slashes extends WP_UnitTestCase { $this->assertEquals( wp_unslash( $this->slash_6 ), $post->post_excerpt ); } + /** + * @ticket 27550 + */ + function test_wp_trash_untrash() { + $post = array( + 'post_title' => $this->slash_1, + 'post_content' => $this->slash_3, + 'post_excerpt' => $this->slash_5, + ); + $id = wp_insert_post( wp_slash( $post ) ); + + $trashed = wp_trash_post( $id ); + $this->assertNotEmpty( $trashed ); + + $post = get_post( $id ); + + $this->assertEquals( $this->slash_1, $post->post_title ); + $this->assertEquals( $this->slash_3, $post->post_content ); + $this->assertEquals( $this->slash_5, $post->post_excerpt ); + + $untrashed = wp_untrash_post( $id ); + $this->assertNotEmpty( $untrashed ); + + $post = get_post( $id ); + + $this->assertEquals( $this->slash_1, $post->post_title ); + $this->assertEquals( $this->slash_3, $post->post_content ); + $this->assertEquals( $this->slash_5, $post->post_excerpt ); + } }