In `comment_form()`, ensure that filtered arguments contain all required default values.

props boonebgorges.
fixes #32312 for trunk.

git-svn-id: https://develop.svn.wordpress.org/trunk@32511 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2015-05-19 01:03:39 +00:00
parent 03e04a0c1c
commit 09bd58b4c9
2 changed files with 31 additions and 0 deletions

View File

@ -2252,6 +2252,9 @@ function comment_form( $args = array(), $post_id = null ) {
*/
$args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
// Ensure that the filtered args contain all required default values.
$args = array_merge( $defaults, $args );
if ( comments_open( $post_id ) ) : ?>
<?php
/**

View File

@ -52,4 +52,32 @@ class Tests_Comment_CommentForm extends WP_UnitTestCase {
$hidden = get_comment_id_fields( $p );
$this->assertRegExp( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
}
/**
* @ticket 32312
*/
public function test_submit_button_and_submit_field_should_fall_back_on_defaults_when_filtered_defaults_do_not_contain_the_keys() {
$p = $this->factory->post->create();
$args = array(
'name_submit' => 'foo-name',
'id_submit' => 'foo-id',
'class_submit' => 'foo-class',
'label_submit' => 'foo-label',
);
add_filter( 'comment_form_defaults', array( $this, 'filter_comment_form_defaults' ) );
$form = get_echo( 'comment_form', array( $args, $p ) );
remove_filter( 'comment_form_defaults', array( $this, 'filter_comment_form_defaults' ) );
$button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
$hidden = get_comment_id_fields( $p );
$this->assertRegExp( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
}
public function filter_comment_form_defaults( $defaults ) {
unset( $defaults['submit_field'] );
unset( $defaults['submit_button'] );
return $defaults;
}
}