Make WordPress Core


Ignore:
Timestamp:
08/12/2022 12:09:10 PM (22 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-includes/general-template.php

    r53846 r53888  
    50235023
    50245024/**
     5025 * Assigns a visual indicator for required form fields.
     5026 *
     5027 * @since 6.1.0
     5028 *
     5029 * @return string Indicator glyph wrapped in a `span` tag.
     5030 */
     5031function wp_required_field_indicator() {
     5032    /* translators: Character to identify required form fields. */
     5033    $glyph     = __( '*' );
     5034    $indicator = '<span class="required" aria-hidden="true">' . esc_html( $glyph ) . '</span>';
     5035
     5036    return $indicator;
     5037}
     5038
     5039/**
     5040 * Creates a message to explain required form fields.
     5041 *
     5042 * @since 6.1.0
     5043 *
     5044 * @return string Message text and glyph wrapped in a `span` tag.
     5045 */
     5046function wp_required_field_message() {
     5047    $message = sprintf(
     5048        '<span class="required-field-message" aria-hidden="true">%s</span>',
     5049        /* translators: %s: Asterisk symbol (*). */
     5050        sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() )
     5051    );
     5052
     5053    return $message;
     5054}
     5055
     5056/**
    50255057 * Default settings for heartbeat.
    50265058 *
Note: See TracChangeset for help on using the changeset viewer.