diff --git src/wp-includes/comment-template.php src/wp-includes/comment-template.php
index 766548f6a0..9c9def4427 100644
|
|
|
function comment_form( $args = array(), $post_id = null ) {
|
| 2512 | 2512 | // Prepare an array of all fields, including the textarea |
| 2513 | 2513 | $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields']; |
| 2514 | 2514 | |
| | 2515 | /** |
| | 2516 | * Check for the presence of id="email-notes" in the |
| | 2517 | * comment_notes_before to remove aria-describedby in the |
| | 2518 | * email field. |
| | 2519 | * |
| | 2520 | * @since 5.3.0 |
| | 2521 | */ |
| | 2522 | if( false === strpos( $args['comment_notes_before'], 'id="email-notes"' ) ) { |
| | 2523 | $comment_fields['email'] = str_replace( |
| | 2524 | ' aria-describedby="email-notes"', |
| | 2525 | '', |
| | 2526 | $comment_fields['email'] |
| | 2527 | ); |
| | 2528 | } |
| | 2529 | |
| 2515 | 2530 | /** |
| 2516 | 2531 | * Filters the comment form fields, including the textarea. |
| 2517 | 2532 | * |
diff --git tests/phpunit/tests/comment/commentForm.php tests/phpunit/tests/comment/commentForm.php
index 0fabd97a6a..731490e430 100644
|
|
|
class Tests_Comment_CommentForm extends WP_UnitTestCase {
|
| 100 | 100 | |
| 101 | 101 | $this->assertRegExp( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form ); |
| 102 | 102 | } |
| | 103 | |
| | 104 | /** |
| | 105 | * aria-describedby="email-notes" should not be displayed if no email notes in `comment_form()`. |
| | 106 | * |
| | 107 | * @ticket 47975 |
| | 108 | */ |
| | 109 | public function test_aria_describedby_email_notes() { |
| | 110 | $p = self::factory()->post->create(); |
| | 111 | |
| | 112 | $comment_form_with_aria = get_echo( 'comment_form', array( array(), $p ) ); |
| | 113 | $with_aria = strpos( $comment_form_with_aria, 'aria-describedby="email-notes"'); |
| | 114 | $this->assertNotFalse( $with_aria ); |
| | 115 | |
| | 116 | // Remove email notes. |
| | 117 | add_filter( 'comment_form_defaults', array( $this, 'filter_remove_email_notes' ) ); |
| | 118 | $comment_form_without_aria = get_echo( 'comment_form', array( array(), $p ) ); |
| | 119 | $without_aria = strpos( $comment_form_without_aria, 'aria-describedby="email-notes"'); |
| | 120 | $this->assertFalse( $without_aria ); |
| | 121 | } |
| | 122 | |
| | 123 | public function filter_remove_email_notes( $defaults ) { |
| | 124 | $defaults['comment_notes_before'] = ''; |
| | 125 | return $defaults; |
| | 126 | } |
| 103 | 127 | } |