Make WordPress Core

Ticket #14773: 12456.4.diff

File 12456.4.diff, 2.2 KB (added by atimmer, 11 years ago)
  • src/wp-includes/canonical.php

     
    225225                }
    226226
    227227                // Post Paging
    228                 if ( is_singular() && ! is_front_page() && get_query_var('page') ) {
    229                         if ( !$redirect_url )
    230                                 $redirect_url = get_permalink( get_queried_object_id() );
    231                         $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
    232                         $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     228                if ( is_singular() && ! is_front_page() ) {
     229                        if ( get_query_var('page') ) {
     230                                if ( ! $redirect_url )
     231                                        $redirect_url = set_url_scheme( get_permalink( get_queried_object_id() ) );
     232                                $redirect_url = trailingslashit( $redirect_url ) . user_trailingslashit( get_query_var( 'page' ), 'single_paged' );
     233                                $redirect['query'] = remove_query_arg( 'page', $redirect['query'] );
     234                        } else {
     235                                $post_url = set_url_scheme( get_permalink( get_queried_object_id() ) );
     236                                // If the full post's URL is not within the requested url, lets redirect there.
     237                                if ( strpos( $requested_url, $post_url ) === false )
     238                                        $redirect_url = $post_url;
     239                        }
    233240                }
    234241
    235242                // paging and feeds
  • tests/phpunit/tests/canonical.php

     
    196196                        // Pages
    197197                        array( '/sample%20page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 17653 ), // Page rules always set 'page'
    198198                        array( '/sample------page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
     199                        array( '/sample-page---/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
     200                        array( '/---sample-page/', array( 'url' => '/sample-page/', 'qv' => array('pagename' => 'sample-page', 'page' => '' ) ), 14773 ),
    199201                        array( '/child-page-1/', '/parent-page/child-page-1/'),
    200202                        array( '/?page_id=144', '/parent-page/child-page-1/'),
    201203                        array( '/abo', '/about/' ),