From 32225077fcdaa1965e6a18c333549ace0afb591f Mon Sep 17 00:00:00 2001 From: Tonya Mork Date: Tue, 16 Nov 2021 02:13:25 +0000 Subject: [PATCH] Comments: Don't output "cancel comment reply link" if comments aren't threaded. Though hidden via `style="display:none;"`, if the comments aren't threaded, this commit doesn't output the cancel comment reply link (skips over that logic). Change in `comment_form()`. Adds tests. Follow-up to [12810], [38959]. Props henrywright, jigneshnakrani, rachelbaker, desrosj, audrasjb, hellofromTonya. Fixes #37267. git-svn-id: https://develop.svn.wordpress.org/trunk@52175 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/comment-template.php | 8 ++++-- tests/phpunit/tests/comment/commentForm.php | 31 ++++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/comment-template.php b/src/wp-includes/comment-template.php index 7549316b78..e056d7b2db 100644 --- a/src/wp-includes/comment-template.php +++ b/src/wp-includes/comment-template.php @@ -2538,11 +2538,13 @@ function comment_form( $args = array(), $post_id = null ) { comment_form_title( $args['title_reply'], $args['title_reply_to'] ); - echo $args['cancel_reply_before']; + if ( get_option( 'thread_comments' ) ) { + echo $args['cancel_reply_before']; - cancel_comment_reply_link( $args['cancel_reply_link'] ); + cancel_comment_reply_link( $args['cancel_reply_link'] ); - echo $args['cancel_reply_after']; + echo $args['cancel_reply_after']; + } echo $args['title_reply_after']; diff --git a/tests/phpunit/tests/comment/commentForm.php b/tests/phpunit/tests/comment/commentForm.php index c5cdf5849b..eef2e9ac7c 100644 --- a/tests/phpunit/tests/comment/commentForm.php +++ b/tests/phpunit/tests/comment/commentForm.php @@ -1,9 +1,16 @@ post->create(); + } + public function test_default_markup_for_submit_button_and_wrapper() { $p = self::factory()->post->create(); @@ -123,4 +130,26 @@ class Tests_Comment_CommentForm extends WP_UnitTestCase { $this->assertStringNotContainsString( 'aria-describedby="email-notes"', $form_without_aria ); } + + /** + * @ticket 32767 + */ + public function test_when_thread_comments_enabled() { + update_option( 'thread_comments', true ); + + $form = get_echo( 'comment_form', array( array(), self::$post_id ) ); + $expected = ''; + $this->assertStringContainsString( $expected, $form ); + } + + /** + * @ticket 32767 + */ + public function test_when_thread_comments_disabled() { + delete_option( 'thread_comments' ); + + $form = get_echo( 'comment_form', array( array(), self::$post_id ) ); + $expected = ''; + $this->assertStringNotContainsString( $expected, $form ); + } }