Make WordPress Core

Ticket #54394: 53494.2.patch

File 53494.2.patch, 4.3 KB (added by sabernhardt, 5 years ago)

using a second argument to determine whether to echo each function instead of creating two more functions, plus including adjustments to comment template file

  • src/wp-includes/comment-template.php

     
    23572357        $required_attribute = ( $html5 ? ' required' : ' required="required"' );
    23582358        $checked_attribute  = ( $html5 ? ' checked' : ' checked="checked"' );
    23592359
    2360         // Identify required fields visually.
    2361         $required_indicator = ' <span class="required" aria-hidden="true">*</span>';
    2362 
    23632360        $fields = array(
    23642361                'author' => sprintf(
    23652362                        '<p class="comment-form-author">%s %s</p>',
     
    23662363                        sprintf(
    23672364                                '<label for="author">%s%s</label>',
    23682365                                __( 'Name' ),
    2369                                 ( $req ? $required_indicator : '' )
     2366                                ( $req ? wp_required_field_indicator() : '' )
    23702367                        ),
    23712368                        sprintf(
    23722369                                '<input id="author" name="author" type="text" value="%s" size="30" maxlength="245"%s />',
     
    23792376                        sprintf(
    23802377                                '<label for="email">%s%s</label>',
    23812378                                __( 'Email' ),
    2382                                 ( $req ? $required_indicator : '' )
     2379                                ( $req ? wp_required_field_indicator() : '' )
    23832380                        ),
    23842381                        sprintf(
    23852382                                '<input id="email" name="email" %s value="%s" size="30" maxlength="100" aria-describedby="email-notes"%s />',
     
    24232420                }
    24242421        }
    24252422
    2426         $required_text = sprintf(
    2427                 /* translators: %s: Asterisk symbol (*). */
    2428                 ' <span class="comment-required-message" aria-hidden="true">' . __( 'Required fields are marked %s' ) . '</span>',
    2429                 trim( $required_indicator )
    2430         );
    2431 
    24322423        /**
    24332424         * Filters the default comment form fields.
    24342425         *
     
    24452436                        sprintf(
    24462437                                '<label for="comment">%s%s</label>',
    24472438                                _x( 'Comment', 'noun' ),
    2448                                 $required_indicator
     2439                                wp_required_field_indicator()
    24492440                        ),
    24502441                        '<textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525"' . $required_attribute . '></textarea>'
    24512442                ),
     
    24702461                                /** This filter is documented in wp-includes/link-template.php */
    24712462                                wp_logout_url( apply_filters( 'the_permalink', get_permalink( $post_id ), $post_id ) )
    24722463                        ),
    2473                         $required_text
     2464                        wp_required_field_message()
    24742465                ),
    24752466                'comment_notes_before' => sprintf(
    24762467                        '<p class="comment-notes">%s%s</p>',
     
    24782469                                '<span id="email-notes">%s</span>',
    24792470                                __( 'Your email address will not be published.' )
    24802471                        ),
    2481                         $required_text
     2472                        wp_required_field_message()
    24822473                ),
    24832474                'comment_notes_after'  => '',
    24842475                'action'               => site_url( '/wp-comments-post.php' ),
  • src/wp-includes/functions.php

     
    83288328function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
    83298329        return abs( (float) $expected - (float) $actual ) <= $precision;
    83308330}
     8331
     8332/**
     8333 * Assign a visual indicator for required form fields.
     8334 *
     8335 * @since 6.0.0
     8336 *
     8337 * @param string $space_before Space character, entity or empty string to add before glyph. Default ' '.
     8338 * @param bool   $echo         Whether to output the result or instead return it. Default false.
     8339 * @return string Indicator glyph wrapped in a `span` tag.
     8340 */
     8341function wp_required_field_indicator( $space_before = ' ', $echo = false ) {
     8342        /* translators: Character to identify required form fields. */
     8343        $glyph     = __( '*' ); // Can be filtered, too (see #23870).
     8344        $indicator = sprintf(
     8345                '%1$s<span class="required" aria-hidden="true">%2$s</span>',
     8346                esc_html( $space_before ),
     8347                esc_html( $glyph ),
     8348        );
     8349
     8350        if ( ! $echo ) {
     8351                return $indicator;
     8352        }
     8353        echo $indicator;
     8354}
     8355
     8356/**
     8357 * Create a message to explain required form fields.
     8358 *
     8359 * @since 6.0.0
     8360 *
     8361 * @param string $space_before Space character, entity or empty string to add before glyph. Default ' '.
     8362 * @param bool   $echo         Whether to output the result or instead return it. Default false.
     8363 * @return string Message text and glyph wrapped in a `span` tag.
     8364 */
     8365function wp_required_field_message( $space_before = ' ', $echo = false ) {
     8366        $message = sprintf(
     8367                '%1$s<span class="required-field-message" aria-hidden="true">%2$s</span>',
     8368                esc_html( $space_before ),
     8369                /* translators: %s: Asterisk symbol (*). */
     8370                sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator( '' ) ),
     8371        );
     8372
     8373        if ( ! $echo ) {
     8374                return $message;
     8375        }
     8376        echo $message;
     8377}