Make WordPress Core

Ticket #16557: 16557.diff

File 16557.diff, 1.6 KB (added by simonwheatley, 9 years ago)

Refresh patch, rename filter, add test

  • src/wp-includes/canonical.php

     
    136136                }
    137137
    138138                if ( ! $redirect_url ) {
    139                         if ( $redirect_url = redirect_guess_404_permalink() ) {
     139                        $redirect_url = apply_filters( '404_redirect', $redirect_url );
     140                        if ( $redirect_url ) {
    140141                                $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 );
    141142                        }
    142143                }
     
    553554        return false;
    554555}
    555556
     557add_filter( '404_redirect', 'redirect_guess_404_permalink' );
     558
    556559add_action('template_redirect', 'redirect_canonical');
    557560
    558561function wp_redirect_admin_locations() {
  • tests/phpunit/tests/canonical.php

     
    280280                        // Todo: Endpoints (feeds, trackbacks, etc), More fuzzed mixed query variables, comment paging, Home page (Static)
    281281                );
    282282        }
     283
     284
     285        /**
     286         * @ticket 16557
     287         */
     288        public function test_guess_redirect() {
     289                // Fake a 404
     290                $GLOBALS[ 'wp_query' ]->is_404 = true;
     291
     292                // Fake a request to /child-page-1/
     293                set_query_var( 'name', 'child-page-1' );
     294
     295                $test_url = '/child-page-1/';
     296                $expected = '/child-page-1/';
     297
     298                remove_filter( '404_redirect', 'redirect_guess_404_permalink' );
     299
     300                $this->test( $test_url, $expected, 16557 );
     301
     302        }
     303
    283304}