Make WordPress Core


Ignore:
Timestamp:
08/12/2022 12:09:10 PM (20 months ago)
Author:
audrasjb
Message:

General: Add required fields helper functions for better reusability.

This changeset introduces new wp_required_field_indicator() and wp_required_field_message() helper functions to generate reusable and consistent required field indicator and message. It also implements these functions in various admin screens.

Props sabernhardt, ryokuhi, joedolson, audrasjb, SergeyBiryukov.
Fixes #54394.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/media.php

    r53777 r53888  
    17041704        <tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n
    17051705        <tr><td colspan='2'><p class='media-types media-types-required-info'>" .
    1706             /* translators: %s: Asterisk symbol (*). */
    1707             sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
     1706            wp_required_field_message() .
    17081707        "</p></td></tr>\n";
    17091708
     
    17851784        }
    17861785
    1787         $required      = $field['required'] ? '<span class="required">*</span>' : '';
     1786        $required      = $field['required'] ? ' ' . wp_required_field_indicator() : '';
    17881787        $required_attr = $field['required'] ? ' required' : '';
    17891788        $class         = $id;
     
    19761975
    19771976        $readonly      = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
    1978         $required      = $field['required'] ? '<span class="required">*</span>' : '';
     1977        $required      = $field['required'] ? ' ' . wp_required_field_indicator() : '';
    19791978        $required_attr = $field['required'] ? ' required' : '';
    19801979        $class         = 'compat-field-' . $id;
     
    20322031    if ( $item ) {
    20332032        $item = '<p class="media-types media-types-required-info">' .
    2034             /* translators: %s: Asterisk symbol (*). */
    2035             sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
     2033            wp_required_field_message() .
    20362034            '</p>' .
    20372035            '<table class="compat-attachment-fields">' . $item . '</table>';
     
    29302928    <p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> &nbsp; &nbsp; <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p>
    29312929    <p class="media-types media-types-required-info">' .
    2932         /* translators: %s: Asterisk symbol (*). */
    2933         sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
     2930        wp_required_field_message() .
    29342931    '</p>
    29352932    <table class="describe ' . $table_class . '"><tbody>
    29362933        <tr>
    29372934            <th scope="row" class="label" style="width:130px;">
    2938                 <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label>
     2935                <label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> ' . wp_required_field_indicator() . '</label>
    29392936                <span class="alignright" id="status_img"></span>
    29402937            </th>
     
    29442941        <tr>
    29452942            <th scope="row" class="label">
    2946                 <label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label>
     2943                <label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> ' . wp_required_field_indicator() . '</label>
    29472944            </th>
    29482945            <td class="field"><input id="title" name="title" value="" type="text" required /></td>
     
    29532950        <tr class="image-only">
    29542951            <th scope="row" class="label">
    2955                 <label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span></label>
     2952                <label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span> ' . wp_required_field_indicator() . '</label>
    29562953            </th>
    29572954            <td class="field"><input id="alt" name="alt" value="" type="text" required />
Note: See TracChangeset for help on using the changeset viewer.