From 612b9e8ffde4687b46f4733afd0dc95963388804 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sat, 14 Feb 2015 03:48:27 +0000 Subject: [PATCH] Replace hardcoded usage of `comment-page` with the comment pagination base. props johnbillion, SergeyBiryukov, webord. fixes #18084. Built from https://develop.svn.wordpress.org/trunk@31459 git-svn-id: http://core.svn.wordpress.org/trunk@31440 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/canonical.php | 6 +++--- wp-includes/comment-template.php | 2 +- wp-includes/link-template.php | 6 +++--- wp-includes/rewrite.php | 11 ++++++++++- wp-includes/version.php | 2 +- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/wp-includes/canonical.php b/wp-includes/canonical.php index 4e247a945f..e4d87f95f1 100644 --- a/wp-includes/canonical.php +++ b/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/wp-includes/comment-template.php b/wp-includes/comment-template.php index fd31591ce5..d05f684248 100644 --- a/wp-includes/comment-template.php +++ b/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/wp-includes/link-template.php b/wp-includes/link-template.php index 17748ddabc..9c0ffec31b 100644 --- a/wp-includes/link-template.php +++ b/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/wp-includes/rewrite.php b/wp-includes/rewrite.php index 984fbbed10..252922851e 100644 --- a/wp-includes/rewrite.php +++ b/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 ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 6792f1c8db..f6ddfce006 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.2-alpha-31458'; +$wp_version = '4.2-alpha-31459'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.