Ticket #16557: 16557.2.diff
File 16557.2.diff, 2.4 KB (added by , 9 years ago) |
---|
-
src/wp-includes/canonical.php
135 135 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'year', 'monthnum' ), $redirect_url ); 136 136 } 137 137 138 if ( ! $redirect_url ) { 139 if ( $redirect_url = redirect_guess_404_permalink() ) { 140 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); 141 } 138 /** 139 * Filter the canonical redirect URL used in the event of a 404. 140 * 141 * @since 4.2.0 142 * 143 * @param string $redirect_url Canonical 404 redirect URL. 144 */ 145 if ( ! apply_filters( '404_redirect', $redirect_url ) ) { 146 $redirect['query'] = _remove_qs_args_if_not_in_url( $redirect['query'], array( 'page', 'feed', 'p', 'page_id', 'attachment_id', 'pagename', 'name', 'post_type' ), $redirect_url ); 142 147 } 143 148 144 149 } elseif ( is_object($wp_rewrite) && $wp_rewrite->using_permalinks() ) { -
src/wp-includes/default-filters.php
374 374 add_action( 'init', 'wp_schedule_update_checks' ); 375 375 376 376 // Canonical 377 add_filter( '404_redirect', 'redirect_guess_404_permalink' ); 377 378 add_action( 'template_redirect', 'redirect_canonical' ); 378 379 add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 ); 379 380 -
tests/phpunit/tests/canonical.php
149 149 // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static) 150 150 ); 151 151 } 152 153 154 /** 155 * @ticket 16557 156 */ 157 public function test_guess_redirect() { 158 // Fake a 404 159 $GLOBALS[ 'wp_query' ]->is_404 = true; 160 161 // Fake a request to /child-page-1/ 162 set_query_var( 'name', 'child-page-1' ); 163 164 $test_url = '/child-page-1/'; 165 $expected = '/child-page-1/'; 166 167 remove_filter( '404_redirect', 'redirect_guess_404_permalink' ); 168 169 $this->test( $test_url, $expected, 16557 ); 170 171 } 172 152 173 }