Skip to content

Commit 5aac59d

Browse files
Replace hardcoded usage of comment-page with the comment pagination base.
props johnbillion, SergeyBiryukov, webord. fixes #18084. git-svn-id: https://develop.svn.wordpress.org/trunk@31459 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 4138275 commit 5aac59d

4 files changed

Lines changed: 17 additions & 8 deletions

File tree

src/wp-includes/canonical.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
254254

255255
// paging and feeds
256256
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'] ) ) {
257+
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'] ) ) {
258258
// Strip off paging and feed
259259
$redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging
260260
$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
261+
$redirect['path'] = preg_replace("#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing comment paging
262262
}
263263

264264
$addl_path = '';
@@ -302,7 +302,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) {
302302
}
303303

304304
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' );
305+
$addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' );
306306
$redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] );
307307
}
308308

src/wp-includes/comment-template.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ function get_comment_link( $comment = null, $args = array() ) {
658658
$args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
659659

660660
if ( $wp_rewrite->using_permalinks() )
661-
$link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
661+
$link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' );
662662
else
663663
$link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
664664
} else {

src/wp-includes/link-template.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,13 +2424,13 @@ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) {
24242424
if ( 'newest' == get_option('default_comments_page') ) {
24252425
if ( $pagenum != $max_page ) {
24262426
if ( $wp_rewrite->using_permalinks() )
2427-
$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
2427+
$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
24282428
else
24292429
$result = add_query_arg( 'cpage', $pagenum, $result );
24302430
}
24312431
} elseif ( $pagenum > 1 ) {
24322432
if ( $wp_rewrite->using_permalinks() )
2433-
$result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged');
2433+
$result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged');
24342434
else
24352435
$result = add_query_arg( 'cpage', $pagenum, $result );
24362436
}
@@ -2573,7 +2573,7 @@ function paginate_comments_links($args = array()) {
25732573
'add_fragment' => '#comments'
25742574
);
25752575
if ( $wp_rewrite->using_permalinks() )
2576-
$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged');
2576+
$defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged');
25772577

25782578
$args = wp_parse_args( $args, $defaults );
25792579
$page_links = paginate_links( $args );

src/wp-includes/rewrite.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,15 @@ class WP_Rewrite {
503503
*/
504504
public $pagination_base = 'page';
505505

506+
/**
507+
* Comments pagination permalink base.
508+
*
509+
* @since 4.2.0
510+
* @access private
511+
* @var string
512+
*/
513+
var $comments_pagination_base = 'comment-page';
514+
506515
/**
507516
* Feed permalink base.
508517
*
@@ -1256,7 +1265,7 @@ public function generate_rewrite_rules($permalink_structure, $ep_mask = EP_NONE,
12561265
//build a regex to match the trackback and page/xx parts of URLs
12571266
$trackbackregex = 'trackback/?$';
12581267
$pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
1259-
$commentregex = 'comment-page-([0-9]{1,})/?$';
1268+
$commentregex = $this->comments_pagination_base . '-([0-9]{1,})/?$';
12601269

12611270
//build up an array of endpoint regexes to append => queries to append
12621271
if ( $endpoints ) {

0 commit comments

Comments
 (0)