Make WordPress Core

Changeset 31699


Ignore:
Timestamp:
03/10/2015 07:07:31 PM (9 years ago)
Author:
boonebgorges
Message:

Improved customizability for the Submit button in comment_form().

The new 'submit_button' and 'submit_field' parameters for comment_form()
allow developers to modify the markup of the submit button and its wrapper.
These params are accompanied by targeted 'comment_form_submit_button' and
'comment_form_submit_field' filters on the concatenated markup.

Props coffee2code, morpheu5, DrewAPicture, boonebgorges.
Fixes #15015.

Location:
trunk
Files:
1 added
1 edited

Legend:

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

    r31518 r31699  
    21542154 *
    21552155 * @since 3.0.0
     2156 * @since 4.2.0 Introduced 'submit_button' and 'submit_fields' arguments.
    21562157 *
    21572158 * @param array       $args {
     
    21812182 *     @type string $cancel_reply_link    The translatable 'cancel reply' button label. Default 'Cancel reply'.
    21822183 *     @type string $label_submit         The translatable 'submit' button label. Default 'Post a comment'.
     2184 *     @type string $submit_button        HTML format for the Submit button.
     2185 *                                        Default: '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />'.
     2186 *     @type string $submit_field         HTML format for the markup surrounding the Submit button and comment hidden
     2187 *                                        fields. Default: '<p class="form-submit">%1$s %2$s</a>', where %1$s is the
     2188 *                                        submit button markup and %2$s is the comment hidden fields.
    21832189 *     @type string $format               The comment form format. Default 'xhtml'. Accepts 'xhtml', 'html5'.
    21842190 * }
     
    22372243        'cancel_reply_link'    => __( 'Cancel reply' ),
    22382244        'label_submit'         => __( 'Post Comment' ),
     2245        'submit_button'        => '<input name="%1$s" type="submit" id="%2$s" class="%3$s" value="%4$s" />',
     2246        'submit_field'         => '<p class="form-submit">%1$s %2$s</p>',
    22392247        'format'               => 'xhtml',
    22402248    );
     
    23512359                        ?>
    23522360                        <?php echo $args['comment_notes_after']; ?>
    2353                         <p class="form-submit">
    2354                             <input name="<?php echo esc_attr( $args['name_submit'] ); ?>" type="submit" id="<?php echo esc_attr( $args['id_submit'] ); ?>" class="<?php echo esc_attr( $args['class_submit'] ); ?>" value="<?php echo esc_attr( $args['label_submit'] ); ?>" />
    2355                             <?php comment_id_fields( $post_id ); ?>
    2356                         </p>
     2361
    23572362                        <?php
     2363                        $submit_button = sprintf(
     2364                            $args['submit_button'],
     2365                            esc_attr( $args['name_submit'] ),
     2366                            esc_attr( $args['id_submit'] ),
     2367                            esc_attr( $args['class_submit'] ),
     2368                            esc_attr( $args['label_submit'] )
     2369                        );
     2370
     2371                        /**
     2372                         * Filter the submit button for the comment form to display.
     2373                         *
     2374                         * @since 4.2.0
     2375                         *
     2376                         * @param string $submit_button HTML markup for the submit button.
     2377                         * @param array  $args          Arguments passed to `comment_form()`.
     2378                         */
     2379                        $submit_button = apply_filters( 'comment_form_submit_button', $submit_button, $args );
     2380
     2381                        $submit_field = sprintf(
     2382                            $args['submit_field'],
     2383                            $submit_button,
     2384                            get_comment_id_fields( $post_id )
     2385                        );
     2386
     2387                        /**
     2388                         * Filter the submit field for the comment form to display.
     2389                         *
     2390                         * The submit field includes the submit button, hidden fields for the
     2391                         * comment form, and any wrapper markup.
     2392                         *
     2393                         * @since 4.2.0
     2394                         *
     2395                         * @param string $submit_field HTML markup for the submit field.
     2396                         * @param array  $args         Arguments passed to `comment_form()`.
     2397                         */
     2398                        echo apply_filters( 'comment_form_submit_field', $submit_field, $args );
     2399
    23582400                        /**
    23592401                         * Fires at the bottom of the comment form, inside the closing </form> tag.
Note: See TracChangeset for help on using the changeset viewer.