WordPress.org

Make WordPress Core

Changeset 32511


Ignore:
Timestamp:
05/19/2015 01:03:39 AM (6 years ago)
Author:
SergeyBiryukov
Message:

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

props boonebgorges.
fixes #32312 for trunk.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/comment-template.php

    r32333 r32511  
    22522252     */
    22532253    $args = wp_parse_args( $args, apply_filters( 'comment_form_defaults', $defaults ) );
     2254
     2255    // Ensure that the filtered args contain all required default values.
     2256    $args = array_merge( $defaults, $args );
    22542257
    22552258        if ( comments_open( $post_id ) ) : ?>
  • trunk/tests/phpunit/tests/comment/commentForm.php

    r31699 r32511  
    5353        $this->assertRegExp( '|<p class="my\-custom\-submit\-field">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
    5454    }
     55
     56    /**
     57     * @ticket 32312
     58     */
     59    public function test_submit_button_and_submit_field_should_fall_back_on_defaults_when_filtered_defaults_do_not_contain_the_keys() {
     60        $p = $this->factory->post->create();
     61
     62        $args = array(
     63            'name_submit' => 'foo-name',
     64            'id_submit' => 'foo-id',
     65            'class_submit' => 'foo-class',
     66            'label_submit' => 'foo-label',
     67        );
     68
     69        add_filter( 'comment_form_defaults', array( $this, 'filter_comment_form_defaults' ) );
     70        $form = get_echo( 'comment_form', array( $args, $p ) );
     71        remove_filter( 'comment_form_defaults', array( $this, 'filter_comment_form_defaults' ) );
     72
     73        $button = '<input name="foo-name" type="submit" id="foo-id" class="foo-class" value="foo-label" />';
     74        $hidden = get_comment_id_fields( $p );
     75        $this->assertRegExp( '|<p class="form\-submit">\s*' . $button . '\s*' . $hidden . '\s*|', $form );
     76    }
     77
     78    public function filter_comment_form_defaults( $defaults ) {
     79        unset( $defaults['submit_field'] );
     80        unset( $defaults['submit_button'] );
     81        return $defaults;
     82    }
    5583}
Note: See TracChangeset for help on using the changeset viewer.