mirror of
git://develop.git.wordpress.org/
synced 2025-01-17 12:58:25 +01:00
Comments: Ensure that themes overriding default comment_form()
fields still display the cookies consent checkbox.
The `comment_form_default_fields` filter can be used to remove the checkbox. Props pross, SergeyBiryukov. Merges [43518] to the 4.9 branch. Fixes #44126. git-svn-id: https://develop.svn.wordpress.org/branches/4.9@43524 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
3e2ca8c151
commit
f1e98d9609
@ -2209,6 +2209,11 @@ function comment_form( $args = array(), $post_id = null ) {
|
||||
$consent = empty( $commenter['comment_author_email'] ) ? '' : ' checked="checked"';
|
||||
$fields['cookies'] = '<p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"' . $consent . ' />' .
|
||||
'<label for="wp-comment-cookies-consent">' . __( 'Save my name, email, and website in this browser for the next time I comment.' ) . '</label></p>';
|
||||
|
||||
// Ensure that the passed fields include cookies consent.
|
||||
if ( isset( $args['fields'] ) && ! isset( $args['fields']['cookies'] ) ) {
|
||||
$args['fields']['cookies'] = $fields['cookies'];
|
||||
}
|
||||
}
|
||||
|
||||
$required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '<span class="required">*</span>' );
|
||||
|
@ -80,4 +80,24 @@ class Tests_Comment_CommentForm extends WP_UnitTestCase {
|
||||
unset( $defaults['submit_button'] );
|
||||
return $defaults;
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 44126
|
||||
*/
|
||||
public function test_fields_should_include_cookies_consent() {
|
||||
$p = self::factory()->post->create();
|
||||
|
||||
add_filter( 'option_show_comments_cookies_opt_in', '__return_true' );
|
||||
|
||||
$args = array(
|
||||
'fields' => array(
|
||||
'author' => 'Hello World!',
|
||||
),
|
||||
);
|
||||
$form = get_echo( 'comment_form', array( $args, $p ) );
|
||||
|
||||
remove_filter( 'option_show_comments_cookies_opt_in', '__return_true' );
|
||||
|
||||
$this->assertRegExp( '|<p class="comment\-form\-cookies\-consent">.*?</p>|', $form );
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user