Make WordPress Core

Changeset 35723


Ignore:
Timestamp:
11/20/2015 06:55:31 PM (9 years ago)
Author:
SergeyBiryukov
Message:

Comments: In comment_form(), introduce the comment_form_fields filter for comment fields, including the textarea.

Correct the docs for comment_notes_before and comment_notes_after arguments as well as comment_form_before_fields and comment_form_after_fields actions to better describe the current behaviour.

Fixes #34731.

File:
1 edited

Legend:

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

    r35546 r35723  
    20382038 *     @type string $must_log_in          HTML element for a 'must be logged in to comment' message.
    20392039 *     @type string $logged_in_as         HTML element for a 'logged in as [user]' message.
    2040  *     @type string $comment_notes_before HTML element for a message displayed before the comment form.
     2040 *     @type string $comment_notes_before HTML element for a message displayed before the comment fields
     2041 *                                        if the user is not logged in.
    20412042 *                                        Default 'Your email address will not be published.'.
    2042  *     @type string $comment_notes_after  HTML element for a message displayed after the comment form.
     2043 *     @type string $comment_notes_after  HTML element for a message displayed after the textarea field.
    20432044 *     @type string $id_form              The comment form element id attribute. Default 'commentform'.
    20442045 *     @type string $id_submit            The comment submit element id attribute. Default 'submit'.
     
    22152216                    endif;
    22162217
     2218                    // Prepare an array of all fields, including the textarea
     2219                    $comment_fields = array( 'comment' => $args['comment_field'] ) + (array) $args['fields'];
     2220
    22172221                    /**
    2218                      * Filter the content of the comment textarea field for display.
     2222                     * Filter the comment form fields.
    22192223                     *
    2220                      * @since 3.0.0
     2224                     * @since 4.4.0
    22212225                     *
    2222                      * @param string $args_comment_field The content of the comment textarea field.
     2226                     * @param array $comment_fields The comment fields.
    22232227                     */
    2224                     echo apply_filters( 'comment_form_field_comment', $args['comment_field'] );
    2225 
    2226                     echo $args['comment_notes_after'];
    2227 
    2228                     if ( ! is_user_logged_in() ) :
    2229                         /**
    2230                          * Fires before the comment fields in the comment form.
    2231                          *
    2232                          * @since 3.0.0
    2233                          */
    2234                         do_action( 'comment_form_before_fields' );
    2235                         foreach ( (array) $args['fields'] as $name => $field ) {
     2228                    $comment_fields = apply_filters( 'comment_form_fields', $comment_fields );
     2229
     2230                    // Get an array of field names, excluding the textarea
     2231                    $comment_field_keys = array_diff( array_keys( $comment_fields ), array( 'comment' ) );
     2232
     2233                    // Get the first and the last field name, excluding the textarea
     2234                    $first_field = reset( $comment_field_keys );
     2235                    $last_field  = end( $comment_field_keys );
     2236
     2237                    foreach ( $comment_fields as $name => $field ) {
     2238
     2239                        if ( 'comment' === $name ) {
     2240
     2241                            /**
     2242                             * Filter the content of the comment textarea field for display.
     2243                             *
     2244                             * @since 3.0.0
     2245                             *
     2246                             * @param string $args_comment_field The content of the comment textarea field.
     2247                             */
     2248                            echo apply_filters( 'comment_form_field_comment', $field );
     2249
     2250                            echo $args['comment_notes_after'];
     2251
     2252                        } elseif ( ! is_user_logged_in() ) {
     2253
     2254                            if ( $first_field === $name ) {
     2255                                /**
     2256                                 * Fires before the comment fields in the comment form, excluding the textarea.
     2257                                 *
     2258                                 * @since 3.0.0
     2259                                 */
     2260                                do_action( 'comment_form_before_fields' );
     2261                            }
     2262
    22362263                            /**
    22372264                             * Filter a comment form field for display.
     
    22452272                             */
    22462273                            echo apply_filters( "comment_form_field_{$name}", $field ) . "\n";
     2274
     2275                            if ( $last_field === $name ) {
     2276                                /**
     2277                                 * Fires after the comment fields in the comment form, excluding the textarea.
     2278                                 *
     2279                                 * @since 3.0.0
     2280                                 */
     2281                                do_action( 'comment_form_after_fields' );
     2282                            }
    22472283                        }
    2248                         /**
    2249                          * Fires after the comment fields in the comment form.
    2250                          *
    2251                          * @since 3.0.0
    2252                          */
    2253                         do_action( 'comment_form_after_fields' );
    2254 
    2255                     endif;
     2284                    }
    22562285
    22572286                    $submit_button = sprintf(
Note: See TracChangeset for help on using the changeset viewer.