Changeset 37075
- Timestamp:
- 03/23/2016 09:53:44 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/query.php
r36989 r37075 4886 4886 * @global WP_Query $wp_query Global WP_Query instance. 4887 4887 * @global wpdb $wpdb WordPress database abstraction object. 4888 * @global WP_Rewrite $wp_rewrite WordPress rewrite component.4889 4888 */ 4890 4889 function wp_old_slug_redirect() { 4891 global $wp_query, $wp_rewrite; 4892 4893 if ( get_queried_object() ) { 4894 return; 4895 } 4896 4897 if ( '' !== $wp_query->query_vars['name'] ) : 4890 global $wp_query; 4891 4892 if ( is_404() && '' !== $wp_query->query_vars['name'] ) : 4898 4893 global $wpdb; 4899 4894 … … 4937 4932 $link = get_permalink( $id ); 4938 4933 4939 if ( is_feed() ) { 4940 $link = user_trailingslashit( trailingslashit( $link ) . 'feed' ); 4941 } elseif ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged'] > 1 ) { 4934 if ( isset( $GLOBALS['wp_query']->query_vars['paged'] ) && $GLOBALS['wp_query']->query_vars['paged'] > 1 ) { 4942 4935 $link = user_trailingslashit( trailingslashit( $link ) . 'page/' . $GLOBALS['wp_query']->query_vars['paged'] ); 4943 4936 } elseif( is_embed() ) { 4944 4937 $link = user_trailingslashit( trailingslashit( $link ) . 'embed' ); 4945 } elseif ( is_404() ) {4946 // Add rewrite endpoints if necessary.4947 foreach ( $wp_rewrite->endpoints as $endpoint ) {4948 if ( $endpoint[2] && false !== get_query_var( $endpoint[2], false ) ) {4949 $link = user_trailingslashit( trailingslashit( $link ) . $endpoint[1] );4950 }4951 }4952 4938 } 4953 4939 -
trunk/tests/phpunit/tests/rewrite/oldSlugRedirect.php
r36128 r37075 45 45 46 46 $permalink = user_trailingslashit( get_permalink( $this->post_id ) ); 47 48 $this->go_to( $old_permalink );49 wp_old_slug_redirect();50 $this->assertEquals( $permalink, $this->old_slug_redirect_url );51 }52 53 public function test_old_slug_redirect_endpoint() {54 $old_permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'custom-endpoint' );55 56 wp_update_post( array(57 'ID' => $this->post_id,58 'post_name' => 'bar-baz',59 ) );60 61 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'custom-endpoint' );62 63 $this->go_to( $old_permalink );64 $GLOBALS['wp_query']->query_vars['custom-endpoint'] = true;65 wp_old_slug_redirect();66 $this->assertEquals( $permalink, $this->old_slug_redirect_url );67 }68 69 public function test_old_slug_redirect_endpoint_custom_query_var() {70 $old_permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'second-endpoint' );71 72 wp_update_post( array(73 'ID' => $this->post_id,74 'post_name' => 'bar-baz',75 ) );76 77 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'second-endpoint' );78 79 $this->go_to( $old_permalink );80 $GLOBALS['wp_query']->query_vars['custom'] = true;81 wp_old_slug_redirect();82 $this->assertEquals( $permalink, $this->old_slug_redirect_url );83 }84 85 public function test_old_slug_redirect_feed() {86 $old_permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'feed' );87 88 wp_update_post( array(89 'ID' => $this->post_id,90 'post_name' => 'bar-baz',91 ) );92 93 $permalink = user_trailingslashit( trailingslashit( get_permalink( $this->post_id ) ) . 'feed' );94 47 95 48 $this->go_to( $old_permalink );
Note: See TracChangeset
for help on using the changeset viewer.