From 42fe7609c7759b2a6054c635ccaee8b051a0e5a9 Mon Sep 17 00:00:00 2001 From: Boone Gorges Date: Mon, 14 Dec 2015 19:45:45 +0000 Subject: [PATCH] Omit `cpage` query var in comment link if comment pagination is disabled. WP 4.4 changed the way comment pagination is calculated. See #8071. In the context of `get_comment_link()`, these changes introduced a regression that causes `cpage` (or its pretty-permalink correlate `comment-page-x`) to appear in comment links when comment pagination is disabled. The current changeset fixes the regression. Fixes #34946. git-svn-id: https://develop.svn.wordpress.org/trunk@35933 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-template.php | 2 +- tests/phpunit/tests/comment/getCommentLink.php | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 854cbe73b3..84a60dbc4a 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -736,7 +736,7 @@ function get_comment_link( $comment = null, $args = array() ) { } } - if ( $cpage ) { + if ( $cpage && get_option( 'page_comments' ) ) { if ( $wp_rewrite->using_permalinks() ) { if ( $cpage ) { $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage; diff --git a/tests/phpunit/tests/comment/getCommentLink.php b/tests/phpunit/tests/comment/getCommentLink.php index 32c490bdb2..fac5fa0d7f 100644 --- a/tests/phpunit/tests/comment/getCommentLink.php +++ b/tests/phpunit/tests/comment/getCommentLink.php @@ -128,4 +128,16 @@ class Tests_Comment_GetCommentLink extends WP_UnitTestCase { $this->assertContains( 'cpage=3', $found ); } + + /** + * @ticket 34946 + */ + public function test_should_not_contain_comment_page_1_when_pagination_is_disabled() { + $this->set_permalink_structure( '/%postname%/' ); + update_option( 'page_comments', 0 ); + + $found = get_comment_link( self::$comments[1] ); + + $this->assertNotContains( 'comment-page-1', $found ); + } }