From 5aac59d1782a3bc4eddf9d59dc5fa55cc57d4d88 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 14 Feb 2015 03:47:02 +0000 Subject: [PATCH] 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 --- src/wp-includes/canonical.php | 6 +++--- src/wp-includes/comment-template.php | 2 +- src/wp-includes/link-template.php | 6 +++--- src/wp-includes/rewrite.php | 11 ++++++++++- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/canonical.php b/src/wp-includes/canonical.php index 4e247a945f..e4d87f95f1 100644 --- a/src/wp-includes/canonical.php +++ b/src/wp-includes/canonical.php @@ -254,11 +254,11 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { // paging and feeds if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) { - 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'] ) ) { + 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'] ) ) { // Strip off paging and feed $redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging $redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings - $redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging + $redirect['path'] = preg_replace("#/{$wp_rewrite->comments_pagination_base}-[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing comment paging } $addl_path = ''; @@ -302,7 +302,7 @@ function redirect_canonical( $requested_url = null, $do_redirect = true ) { } 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 ) ) ) { - $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( 'comment-page-' . get_query_var('cpage'), 'commentpaged' ); + $addl_path = ( !empty( $addl_path ) ? trailingslashit($addl_path) : '' ) . user_trailingslashit( $wp_rewrite->comments_pagination_base . '-' . get_query_var('cpage'), 'commentpaged' ); $redirect['query'] = remove_query_arg( 'cpage', $redirect['query'] ); } diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index fd31591ce5..d05f684248 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -658,7 +658,7 @@ function get_comment_link( $comment = null, $args = array() ) { $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); if ( $wp_rewrite->using_permalinks() ) - $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ); + $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' ); else $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); } else { diff --git a/src/wp-includes/link-template.php b/src/wp-includes/link-template.php index 17748ddabc..9c0ffec31b 100644 --- a/src/wp-includes/link-template.php +++ b/src/wp-includes/link-template.php @@ -2424,13 +2424,13 @@ function get_comments_pagenum_link( $pagenum = 1, $max_page = 0 ) { if ( 'newest' == get_option('default_comments_page') ) { if ( $pagenum != $max_page ) { if ( $wp_rewrite->using_permalinks() ) - $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); + $result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged'); else $result = add_query_arg( 'cpage', $pagenum, $result ); } } elseif ( $pagenum > 1 ) { if ( $wp_rewrite->using_permalinks() ) - $result = user_trailingslashit( trailingslashit($result) . 'comment-page-' . $pagenum, 'commentpaged'); + $result = user_trailingslashit( trailingslashit($result) . $wp_rewrite->comments_pagination_base . '-' . $pagenum, 'commentpaged'); else $result = add_query_arg( 'cpage', $pagenum, $result ); } @@ -2573,7 +2573,7 @@ function paginate_comments_links($args = array()) { 'add_fragment' => '#comments' ); if ( $wp_rewrite->using_permalinks() ) - $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . 'comment-page-%#%', 'commentpaged'); + $defaults['base'] = user_trailingslashit(trailingslashit(get_permalink()) . $wp_rewrite->comments_pagination_base . '-%#%', 'commentpaged'); $args = wp_parse_args( $args, $defaults ); $page_links = paginate_links( $args ); diff --git a/src/wp-includes/rewrite.php b/src/wp-includes/rewrite.php index 984fbbed10..252922851e 100644 --- a/src/wp-includes/rewrite.php +++ b/src/wp-includes/rewrite.php @@ -503,6 +503,15 @@ class WP_Rewrite { */ public $pagination_base = 'page'; + /** + * Comments pagination permalink base. + * + * @since 4.2.0 + * @access private + * @var string + */ + var $comments_pagination_base = 'comment-page'; + /** * Feed permalink base. * @@ -1256,7 +1265,7 @@ class WP_Rewrite { //build a regex to match the trackback and page/xx parts of URLs $trackbackregex = 'trackback/?$'; $pageregex = $this->pagination_base . '/?([0-9]{1,})/?$'; - $commentregex = 'comment-page-([0-9]{1,})/?$'; + $commentregex = $this->comments_pagination_base . '-([0-9]{1,})/?$'; //build up an array of endpoint regexes to append => queries to append if ( $endpoints ) {