Ticket #23074: 23074.diff
File 23074.diff, 2.3 KB (added by , 10 years ago) |
---|
-
tests/phpunit/tests/post/redirects.php
1 <?php 2 class Tests_Post_Redirects extends WP_UnitTestCase { 3 4 var $post; 5 6 function setUp() { 7 parent::setUp(); 8 $post = array( 9 'post_name' => 'foo', 10 'post_title' => 'Foo', 11 'post_status' => 'publish' 12 ); 13 $post['ID'] = wp_insert_post( $post ); 14 $this->post = $post; 15 } 16 17 function test_old_slugs_private() { 18 $id = $this->post['ID']; 19 $before_post = get_post( $id ); 20 $this->post['post_name'] = 'foobar'; 21 $this->post['post_status'] = 'private'; 22 wp_update_post( $this->post ); 23 $old_slugs = (array) get_post_meta( $id, '_wp_old_slug' ); 24 $this->AssertTrue( in_array( 'foo', $old_slugs ) ); 25 } 26 27 function test_old_slugs_publish() { 28 $id = $this->post['ID']; 29 $this->post['post_name'] = 'foo'; 30 $this->post['post_status'] = 'publish'; 31 wp_update_post( $this->post ); 32 $old_slugs = (array) get_post_meta( $id, '_wp_old_slug' ); 33 $this->AssertFalse( in_array( 'foo', $old_slugs ) ); 34 } 35 36 } 37 No newline at end of file -
src/wp-includes/post.php
5002 5002 */ 5003 5003 function wp_check_for_changed_slugs($post_id, $post, $post_before) { 5004 5004 // dont bother if it hasnt changed 5005 if ( $post->post_name == $post_before->post_name ) 5005 if ( $post->post_name == $post_before->post_name ) { 5006 5006 return; 5007 } 5007 5008 5008 5009 // we're only concerned with published, non-hierarchical objects 5009 if ( $post->post_status != 'publish' || is_post_type_hierarchical( $post->post_type ) )5010 if ( is_post_type_hierarchical( $post->post_type ) ) { 5010 5011 return; 5012 } 5013 5014 $valid_status = array( 5015 'publish', 5016 'private' 5017 ); 5018 if( ! in_array( $post->post_status, $valid_status ) ) { 5019 return; 5020 } 5021 $old_slugs = (array) get_post_meta( $post_id, '_wp_old_slug' ); 5011 5022 5012 $old_slugs = (array) get_post_meta($post_id, '_wp_old_slug');5013 5014 5023 // if we haven't added this old slug before, add it now 5015 5024 if ( !empty( $post_before->post_name ) && !in_array($post_before->post_name, $old_slugs) ) 5016 5025 add_post_meta($post_id, '_wp_old_slug', $post_before->post_name);