Ticket #11863: 11863.4.diff
File 11863.4.diff, 4.9 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/post.php
1226 1226 if ( !is_null($name) ) 1227 1227 $post->post_name = sanitize_title($name ? $name : $title, $post->ID); 1228 1228 1229 if ( $post->post_status != 'trash' && $post->post_name ) { 1230 _add_suffix_to_post_name_for_trashed_posts( $post->post_name ); 1231 } 1229 1232 $post->post_name = wp_unique_post_slug($post->post_name, $post->ID, $post->post_status, $post->post_type, $post->post_parent); 1230 1233 1231 1234 $post->filter = 'sample'; -
src/wp-includes/default-filters.php
475 475 add_filter( 'oembed_dataparse', 'wp_filter_oembed_result', 10, 3 ); 476 476 add_filter( 'oembed_response_data', 'get_oembed_response_data_rich', 10, 4 ); 477 477 478 // Untrashed posts should get their desired post slug. 479 add_action( 'transition_post_status', '_modify_post_name_on_transition_post_status', 5, 3 ); 480 478 481 unset( $filter, $action ); -
src/wp-includes/post.php
3237 3237 */ 3238 3238 $post_parent = apply_filters( 'wp_insert_post_parent', $post_parent, $post_ID, compact( array_keys( $postarr ) ), $postarr ); 3239 3239 3240 if ( $post_status != 'trash' && $post_name ) { 3241 _add_suffix_to_post_name_for_trashed_posts( $post_name ); 3242 } 3243 3240 3244 $post_name = wp_unique_post_slug( $post_name, $post_ID, $post_status, $post_type, $post_parent ); 3241 3245 3242 3246 // Don't unslash. … … 5992 5996 update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache ); 5993 5997 } 5994 5998 } 5999 6000 /** 6001 * When a post is untrashed give a post its desired slug (if it has one). 6002 * 6003 * @since 4.5.0 6004 * @access private 6005 * 6006 * @param string $new_status New post status. 6007 * @param string $old_status Old post status. 6008 * @param WP_Post $post Post object. 6009 */ 6010 function _modify_post_name_on_transition_post_status( $new_status, $old_status, $post ) { 6011 // Only modify `post_name` when untrashing a post. 6012 if ( 'trash' === $new_status || 'trash' !== $old_status ) { 6013 return; 6014 } 6015 $desired_post_slug = get_post_meta( $post->ID, '_wp_desired_post_slug', true ); 6016 delete_post_meta( $post->ID, '_wp_desired_post_slug' ); 6017 if ( ! $desired_post_slug ) { 6018 return; 6019 } 6020 $post->post_name = $desired_post_slug; 6021 wp_update_post( $post ); 6022 } 6023 6024 /** 6025 * If any trashed posts have a given slug, add a suffix. 6026 * 6027 * @since 4.5.0 6028 * @access private 6029 * 6030 * @param string $post_name Slug. 6031 */ 6032 function _add_suffix_to_post_name_for_trashed_posts( $post_name ) { 6033 $trashed_posts_with_desired_slug = get_posts( array( 6034 'name' => $post_name, 6035 'post_status' => 'trash', 6036 'post_type' => 'any', 6037 'nopaging' => true, 6038 ) ); 6039 if ( ! empty( $trashed_posts_with_desired_slug ) ) { 6040 foreach ( $trashed_posts_with_desired_slug as $_post ) { 6041 // Store the desired slug so it can be reapplied if it is untrashed. 6042 add_post_meta( $_post->ID, '_wp_desired_post_slug', $_post->post_name ); 6043 $_post->post_name = _truncate_post_slug( $_post->post_name, 198 ) . "-2"; 6044 wp_update_post( $_post ); 6045 } 6046 } 6047 } -
tests/phpunit/tests/post.php
1258 1258 $this->assertEquals( 0, get_post( $page_id )->post_parent ); 1259 1259 } 1260 1260 1261 /** 1262 * @ticket 11863 1263 */ 1264 function test_trashed_post_slugs_should_move_for_non_trashed_posts() { 1265 $trashed_about_page_id = self::factory()->post->create( array( 1266 'post_type' => 'page', 1267 'post_title' => 'About', 1268 'post_status' => 'publish' 1269 ) ); 1270 wp_trash_post( $trashed_about_page_id ); 1271 $about_page_id = self::factory()->post->create( array( 1272 'post_type' => 'page', 1273 'post_title' => 'About', 1274 'post_status' => 'publish' 1275 ) ); 1276 $this->assertEquals( 'about', get_post( $about_page_id )->post_name ); 1277 $this->assertEquals( 'about-2', get_post( $trashed_about_page_id )->post_name ); 1278 } 1279 1280 /** 1281 * @ticket 11863 1282 */ 1283 function test_trashed_post_slugs_that_were_moved_should_be_reassigned_after_untrashing() { 1284 $about_page_id = self::factory()->post->create( array( 1285 'post_type' => 'page', 1286 'post_title' => 'About', 1287 'post_status' => 'publish' 1288 ) ); 1289 wp_trash_post( $about_page_id ); 1290 $another_about_page_id = self::factory()->post->create( array( 1291 'post_type' => 'page', 1292 'post_title' => 'About', 1293 'post_status' => 'publish' 1294 ) ); 1295 1296 wp_trash_post( $another_about_page_id ); 1297 1298 wp_untrash_post( $about_page_id ); 1299 $this->assertEquals( 'about', get_post( $about_page_id )->post_name ); 1300 } 1261 1301 }