Make WordPress Core

Ticket #54394: 53494.3.patch

File 53494.3.patch, 2.9 KB (added by sabernhardt, 4 years ago)

updating comments form example after r52200

  • 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>';
     2360        // Identify required fields visually and create a message about the indicator.
     2361        $required_indicator = wp_required_field_indicator();
     2362        $required_text      = wp_required_field_message();
    23622363
    23632364        $fields = array(
    23642365                'author' => sprintf(
     
    24232424                }
    24242425        }
    24252426
    2426         $required_text = sprintf(
    2427                 /* translators: %s: Asterisk symbol (*). */
    2428                 ' <span class="required-field-message" aria-hidden="true">' . __( 'Required fields are marked %s' ) . '</span>',
    2429                 trim( $required_indicator )
    2430         );
    2431 
    24322427        /**
    24332428         * Filters the default comment form fields.
    24342429         *
  • src/wp-includes/functions.php

     
    83768376function wp_fuzzy_number_match( $expected, $actual, $precision = 1 ) {
    83778377        return abs( (float) $expected - (float) $actual ) <= $precision;
    83788378}
     8379
     8380/**
     8381 * Assign a visual indicator for required form fields.
     8382 *
     8383 * @since 6.0.0
     8384 *
     8385 * @param string $space_before Space character, entity or empty string to add before glyph. Default ' '.
     8386 * @param bool   $echo         Whether to output the result or instead return it. Default false.
     8387 * @return string Indicator glyph wrapped in a `span` tag.
     8388 */
     8389function wp_required_field_indicator( $space_before = ' ', $echo = false ) {
     8390        /* translators: Character to identify required form fields. */
     8391        $glyph     = __( '*' ); // Can be filtered, too (see #23870).
     8392        $indicator = sprintf(
     8393                '%1$s<span class="required" aria-hidden="true">%2$s</span>',
     8394                esc_html( $space_before ),
     8395                esc_html( $glyph ),
     8396        );
     8397
     8398        if ( ! $echo ) {
     8399                return $indicator;
     8400        }
     8401        echo $indicator;
     8402}
     8403
     8404/**
     8405 * Create a message to explain required form fields.
     8406 *
     8407 * @since 6.0.0
     8408 *
     8409 * @param string $space_before Space character, entity or empty string to add before glyph. Default ' '.
     8410 * @param bool   $echo         Whether to output the result or instead return it. Default false.
     8411 * @return string Message text and glyph wrapped in a `span` tag.
     8412 */
     8413function wp_required_field_message( $space_before = ' ', $echo = false ) {
     8414        $message = sprintf(
     8415                '%1$s<span class="required-field-message" aria-hidden="true">%2$s</span>',
     8416                esc_html( $space_before ),
     8417                /* translators: %s: Asterisk symbol (*). */
     8418                sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator( '' ) ),
     8419        );
     8420
     8421        if ( ! $echo ) {
     8422                return $message;
     8423        }
     8424        echo $message;
     8425}