Ticket #20302: 20302.diff
File 20302.diff, 4.6 KB (added by , 9 years ago) |
---|
-
tests/phpunit/tests/comment/commentsTemplate.php
685 685 $this->assertSame( array( $comment_4, $comment_3 ), $found_cids ); 686 686 } 687 687 688 /** 689 * Validate that the current attributes (action, method, id, class, and novalidate) are 690 * still present after moving to an array-based build. 691 * 692 * @ticket 20302 693 */ 694 public function test_building_comment_form_attributes_from_array() { 695 $p = self::factory()->post->create(); 696 697 add_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); 698 $this->go_to( get_permalink( $p ) ); 699 $template = get_echo( 'comments_template' ); 700 remove_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); 701 702 $this->assertEquals( 1, preg_match( '|\saction="(.+)/wp-comments-post.php"|i', $template ) ); 703 $this->assertContains( 'method="post"', $template ); 704 $this->assertContains( 'id="commentform"', $template ); 705 $this->assertContains( 'class="comment-form"', $template ); 706 } 707 708 /** 709 * @ticket 20302 710 */ 711 public function test_extra_comment_form_attributes() { 712 $p = self::factory()->post->create(); 713 714 /** 715 * Anonymous function to alter the 'attributes' value for the 'comment_form_defaults' filter. 716 */ 717 add_filter( 'comment_form_defaults', function ( $defaults ) { 718 $defaults['attributes'] = array( 719 'data-test-attribute' => 'hooray!', 720 'onclick' => 'dosomething()', 721 ); 722 723 return $defaults; 724 } ); 725 726 add_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); 727 $this->go_to( get_permalink( $p ) ); 728 $template = get_echo( 'comments_template' ); 729 remove_filter( 'wp_get_current_commenter', array( $this, 'fake_current_commenter' ) ); 730 731 // Validate that default attributes aren't overwritten. 732 $this->assertContains( 'method="post"', $template ); 733 $this->assertContains( 'id="commentform"', $template ); 734 $this->assertContains( 'class="comment-form"', $template ); 735 736 // Validate our custom attribute. 737 $this->assertContains( 'data-test-attribute="hooray!"', $template ); 738 $this->assertContains( 'onclick="dosomething()"', $template ); 739 } 740 688 741 public function fake_current_commenter( $commenter ) { 689 742 $commenter['comment_author_email'] = 'foo@example.com'; 690 743 return $commenter; -
src/wp-includes/comment-template.php
1242 1242 * @global int $user_ID 1243 1243 * @global string $user_identity 1244 1244 * @global bool $overridden_cpage 1245 * @global bool $withcomments 1245 * @global bool $withcomments 1246 1246 * 1247 1247 * @param string $file Optional. The file to load. Default '/comments.php'. 1248 1248 * @param bool $separate_comments Optional. Whether to separate the comments by comment type. … … 2089 2089 'submit_button' => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />', 2090 2090 'submit_field' => '<p class="form-submit">%1$s %2$s</p>', 2091 2091 'format' => 'xhtml', 2092 'attributes' => array(), 2092 2093 ); 2093 2094 2094 2095 /** … … 2105 2106 // Ensure that the filtered args contain all required default values. 2106 2107 $args = array_merge( $defaults, $args ); 2107 2108 2109 // Build the <form> attributes. 2110 $attributes = array( 2111 'action' => site_url( '/wp-comments-post.php' ), 2112 'method' => 'post', 2113 'id' => $args['id_form'], 2114 'class' => $args['class_form'], 2115 'novalidate' => $html5, 2116 ); 2117 2118 if ( is_array( $args['attributes'] ) ) { 2119 $attributes = array_merge( $attributes, $args['attributes'] ); 2120 } 2121 2108 2122 if ( comments_open( $post_id ) ) : ?> 2109 2123 <?php 2110 2124 /** … … 2137 2151 */ 2138 2152 do_action( 'comment_form_must_log_in_after' ); 2139 2153 else : ?> 2140 <form action="<?php echo site_url( '/wp-comments-post.php' ); ?>" method="post" id="<?php echo esc_attr( $args['id_form'] ); ?>" class="<?php echo esc_attr( $args['class_form'] ); ?>"<?php echo $html5 ? ' novalidate' : ''; ?>> 2154 <?php 2155 echo '<form'; 2156 2157 // Build the form attributes. 2158 foreach ( $attributes as $attr_name => $attr_val ) { 2159 if ( true === $attr_val ) { 2160 echo ' ' . esc_attr( $attr_name ); 2161 } else { 2162 printf( ' %s="%s"', esc_attr( $attr_name ), esc_attr( $attr_val ) ); 2163 } 2164 } 2165 2166 echo '>'; 2167 ?> 2141 2168 <?php 2142 2169 /** 2143 2170 * Fires at the top of the comment form, inside the form tag.