~canonical-sysadmins/wordpress/4.2.4

« back to all changes in this revision

Viewing changes to wp-includes/canonical.php

  • Committer: Paul Gear
  • Date: 2015-04-24 01:35:20 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: paul.gear@canonical.com-20150424013520-w4p9ksth76zh6opw
Merge new upstream release 4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
        if ( !isset($redirect['query']) )
84
84
                $redirect['query'] = '';
85
85
 
 
86
        // If the original URL ended with non-breaking spaces, they were almost
 
87
        // certainly inserted by accident. Let's remove them, so the reader doesn't
 
88
        // see a 404 error with no obvious cause.
 
89
        $redirect['path'] = preg_replace( '|(%C2%A0)+$|i', '', $redirect['path'] );
 
90
 
86
91
        // It's not a preview, so remove it from URL
87
92
        if ( get_query_var( 'preview' ) ) {
88
93
                $redirect['query'] = remove_query_arg( 'preview', $redirect['query'] );
254
259
 
255
260
                // paging and feeds
256
261
                if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) {
257
 
                        while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $redirect['path'] ) ) {
 
262
                        while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( "#/{$wp_rewrite->comments_pagination_base}-[0-9]+(/+)?$#", $redirect['path'] ) ) {
258
263
                                // Strip off paging and feed
259
264
                                $redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging
260
265
                                $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings
261
 
                                $redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging
 
266
                                $redirect['path'] = preg_replace("#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing comment paging
262
267
                        }
263
268
 
264
269
                        $addl_path = '';
302
307
                        }
303
308
 
304
309
                        if ( get_option('page_comments') && ( ( 'newest' == get_option('default_comments_page') && get_query_var('cpage') > 0 ) || ( 'newest' != get_option('default_comments_page') && get_query_var('cpage') > 1 ) ) ) {
305
 
                                $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' );
 
310
                                $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' );
306
311
                                $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
307
312
                        }
308
313
 
553
558
        return false;
554
559
}
555
560
 
556
 
add_action('template_redirect', 'redirect_canonical');
557
 
 
558
561
function wp_redirect_admin_locations() {
559
562
        global $wp_rewrite;
560
563
        if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) )
582
585
                exit;
583
586
        }
584
587
}
585
 
 
586
 
add_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );