Ticket #23022: 23022.patch
File 23022.patch, 5.1 KB (added by , 7 years ago) |
---|
-
src/wp-admin/edit.php
diff --git src/wp-admin/edit.php src/wp-admin/edit.php index a05d369e1d..fbf04ac0dd 100644
if ( $doaction ) { 132 132 break; 133 133 case 'untrash': 134 134 $untrashed = 0; 135 136 if ( isset( $_GET['doaction'] ) && ( 'undo' === $_GET['doaction'] ) ) { 137 add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 ); 138 } 139 135 140 foreach ( (array) $post_ids as $post_id ) { 136 141 if ( ! current_user_can( 'delete_post', $post_id ) ) { 137 142 wp_die( __( 'Sorry, you are not allowed to restore this item from the Trash.' ) ); … … if ( $doaction ) { 144 149 $untrashed++; 145 150 } 146 151 $sendback = add_query_arg( 'untrashed', $untrashed, $sendback ); 152 153 remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 ); 154 147 155 break; 148 156 case 'delete': 149 157 $deleted = 0; -
src/wp-includes/post.php
diff --git src/wp-includes/post.php src/wp-includes/post.php index 281978eb8d..e62da125d2 100644
function wp_untrash_post( $post_id = 0 ) { 2849 2849 */ 2850 2850 do_action( 'untrash_post', $post_id ); 2851 2851 2852 $post_status = get_post_meta( $post_id, '_wp_trash_meta_status', true ); 2852 $previous_status = get_post_meta( $post_id, '_wp_trash_meta_status', true ); 2853 2854 /** 2855 * Filter the status that a post gets when it is restored from the trash (untrashed). 2856 * 2857 * By default, posts that are restored will be assigned a status of 'draft'. Return the value of `$previous_status` 2858 * in order to assign the status that the post had before it was trashed. The `wp_untrash_post_set_previous_status()` 2859 * function is available for this. 2860 * 2861 * Prior to WordPress 5.0, restored posts were given their original status. 2862 * 2863 * @since 5.0.0 2864 * 2865 * @param string $new_status The new status of the post being restored. 2866 * @param int $post_id The ID of the post being restored. 2867 * @param string $previous_status The status of the post at the point where it was trashed. 2868 */ 2869 $post_status = apply_filters( 'wp_untrash_post_status', 'draft', $post_id, $previous_status ); 2853 2870 2854 2871 delete_post_meta( $post_id, '_wp_trash_meta_status' ); 2855 2872 delete_post_meta( $post_id, '_wp_trash_meta_time' ); … … function _filter_query_attachment_filenames( $clauses ) { 6591 6608 6592 6609 return $clauses; 6593 6610 } 6611 6612 /** 6613 * Filter callback which sets the status of an untrashed post to its previous status. 6614 * 6615 * This can be used as a callback on the `wp_untrash_post_status` filter. 6616 * 6617 * @since 5.0.0 6618 * 6619 * @param string $new_status The new status of the post being restored. 6620 * @param int $post_id The ID of the post being restored. 6621 * @param string $previous_status The status of the post at the point where it was trashed. 6622 * @return string The status of the post at the point where it was trashed. 6623 */ 6624 function wp_untrash_post_set_previous_status( $new_status, $post_id, $previous_status ) { 6625 return $previous_status; 6626 } -
tests/phpunit/tests/post/wpInsertPost.php
diff --git tests/phpunit/tests/post/wpInsertPost.php tests/phpunit/tests/post/wpInsertPost.php index d459d9493d..b2d5bc2378 100644
class Tests_WPInsertPost extends WP_UnitTestCase { 146 146 ); 147 147 148 148 wp_untrash_post( $about_page_id ); 149 wp_update_post( array( 150 'ID' => $about_page_id, 151 'post_status' => 'publish', 152 ) ); 149 153 150 154 $this->assertEquals( 'about', get_post( $another_about_page_id )->post_name ); 151 155 $this->assertEquals( 'about-2', get_post( $about_page_id )->post_name ); 152 156 } 153 157 158 /** 159 * @ticket 23022 160 * @dataProvider data_various_post_statuses 161 */ 162 function test_untrashing_a_post_should_always_restore_it_to_draft_status( $post_status ) { 163 $page_id = self::factory()->post->create( array( 164 'post_type' => 'page', 165 'post_status' => $post_status, 166 ) ); 167 168 wp_trash_post( $page_id ); 169 wp_untrash_post( $page_id ); 170 171 $this->assertEquals( 'draft', get_post( $page_id )->post_status ); 172 } 173 174 /** 175 * @ticket 23022 176 * @dataProvider data_various_post_statuses 177 */ 178 function test_wp_untrash_post_status_filter_restores_post_to_correct_status( $post_status ) { 179 add_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 ); 180 181 $page_id = self::factory()->post->create( array( 182 'post_type' => 'page', 183 'post_status' => $post_status, 184 ) ); 185 186 wp_trash_post( $page_id ); 187 wp_untrash_post( $page_id ); 188 189 remove_filter( 'wp_untrash_post_status', 'wp_untrash_post_set_previous_status', 10, 3 ); 190 191 $this->assertEquals( $post_status, get_post( $page_id )->post_status ); 192 } 193 154 194 /** 155 195 * Data for testing the ability for users to set the post slug. 156 196 * … … class Tests_WPInsertPost extends WP_UnitTestCase { 170 210 ); 171 211 } 172 212 213 /** 214 * Data for testing post statuses. 215 * 216 * @return array Array of test arguments. 217 */ 218 function data_various_post_statuses() { 219 return array( 220 array( 221 'draft', 222 ), 223 array( 224 'pending', 225 ), 226 array( 227 'private', 228 ), 229 array( 230 'publish', 231 ), 232 ); 233 } 234 173 235 /** 174 236 * Test contributor making changes to the pending post slug. 175 237 *