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. Built from https://develop.svn.wordpress.org/trunk@53888 git-svn-id: http://core.svn.wordpress.org/trunk@53447 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
32879ad1e6
commit
e7d91b8017
|
@ -1703,8 +1703,7 @@ function get_media_item( $attachment_id, $args = null ) {
|
|||
<tr><td colspan='2' class='imgedit-response' id='imgedit-response-$post->ID'></td></tr>\n
|
||||
<tr><td style='display:none' colspan='2' class='image-editor' id='image-editor-$post->ID'></td></tr>\n
|
||||
<tr><td colspan='2'><p class='media-types media-types-required-info'>" .
|
||||
/* translators: %s: Asterisk symbol (*). */
|
||||
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
|
||||
wp_required_field_message() .
|
||||
"</p></td></tr>\n";
|
||||
|
||||
$defaults = array(
|
||||
|
@ -1784,7 +1783,7 @@ function get_media_item( $attachment_id, $args = null ) {
|
|||
continue;
|
||||
}
|
||||
|
||||
$required = $field['required'] ? '<span class="required">*</span>' : '';
|
||||
$required = $field['required'] ? ' ' . wp_required_field_indicator() : '';
|
||||
$required_attr = $field['required'] ? ' required' : '';
|
||||
$class = $id;
|
||||
$class .= $field['required'] ? ' form-required' : '';
|
||||
|
@ -1975,7 +1974,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
|||
}
|
||||
|
||||
$readonly = ! $user_can_edit && ! empty( $field['taxonomy'] ) ? " readonly='readonly' " : '';
|
||||
$required = $field['required'] ? '<span class="required">*</span>' : '';
|
||||
$required = $field['required'] ? ' ' . wp_required_field_indicator() : '';
|
||||
$required_attr = $field['required'] ? ' required' : '';
|
||||
$class = 'compat-field-' . $id;
|
||||
$class .= $field['required'] ? ' form-required' : '';
|
||||
|
@ -2031,8 +2030,7 @@ function get_compat_media_markup( $attachment_id, $args = null ) {
|
|||
|
||||
if ( $item ) {
|
||||
$item = '<p class="media-types media-types-required-info">' .
|
||||
/* translators: %s: Asterisk symbol (*). */
|
||||
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
|
||||
wp_required_field_message() .
|
||||
'</p>' .
|
||||
'<table class="compat-attachment-fields">' . $item . '</table>';
|
||||
}
|
||||
|
@ -2929,13 +2927,12 @@ function wp_media_insert_url_form( $default_view = 'image' ) {
|
|||
return '
|
||||
<p class="media-types"><label><input type="radio" name="media_type" value="image" id="image-only"' . checked( 'image-only', $view, false ) . ' /> ' . __( 'Image' ) . '</label> <label><input type="radio" name="media_type" value="generic" id="not-image"' . checked( 'not-image', $view, false ) . ' /> ' . __( 'Audio, Video, or Other File' ) . '</label></p>
|
||||
<p class="media-types media-types-required-info">' .
|
||||
/* translators: %s: Asterisk symbol (*). */
|
||||
sprintf( __( 'Required fields are marked %s' ), '<span class="required">*</span>' ) .
|
||||
wp_required_field_message() .
|
||||
'</p>
|
||||
<table class="describe ' . $table_class . '"><tbody>
|
||||
<tr>
|
||||
<th scope="row" class="label" style="width:130px;">
|
||||
<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> <span class="required">*</span></label>
|
||||
<label for="src"><span class="alignleft">' . __( 'URL' ) . '</span> ' . wp_required_field_indicator() . '</label>
|
||||
<span class="alignright" id="status_img"></span>
|
||||
</th>
|
||||
<td class="field"><input id="src" name="src" value="" type="text" required onblur="addExtImage.getImageData()" /></td>
|
||||
|
@ -2943,7 +2940,7 @@ function wp_media_insert_url_form( $default_view = 'image' ) {
|
|||
|
||||
<tr>
|
||||
<th scope="row" class="label">
|
||||
<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> <span class="required">*</span></label>
|
||||
<label for="title"><span class="alignleft">' . __( 'Title' ) . '</span> ' . wp_required_field_indicator() . '</label>
|
||||
</th>
|
||||
<td class="field"><input id="title" name="title" value="" type="text" required /></td>
|
||||
</tr>
|
||||
|
@ -2952,7 +2949,7 @@ function wp_media_insert_url_form( $default_view = 'image' ) {
|
|||
|
||||
<tr class="image-only">
|
||||
<th scope="row" class="label">
|
||||
<label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span></label>
|
||||
<label for="alt"><span class="alignleft">' . __( 'Alternative Text' ) . '</span> ' . wp_required_field_indicator() . '</label>
|
||||
</th>
|
||||
<td class="field"><input id="alt" name="alt" value="" type="text" required />
|
||||
<p class="help">' . __( 'Alt text for the image, e.g. “The Mona Lisa”' ) . '</p></td>
|
||||
|
|
|
@ -193,20 +193,19 @@ if ( ! empty( $messages ) ) {
|
|||
}
|
||||
}
|
||||
?>
|
||||
<p>
|
||||
<?php
|
||||
printf(
|
||||
/* translators: %s: Asterisk symbol (*). */
|
||||
__( 'Required fields are marked %s' ),
|
||||
'<span class="required">*</span>'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
<p><?php echo wp_required_field_message(); ?></p>
|
||||
<form method="post" action="<?php echo esc_url( network_admin_url( 'site-new.php?action=add-site' ) ); ?>" novalidate="novalidate">
|
||||
<?php wp_nonce_field( 'add-blog', '_wpnonce_add-blog' ); ?>
|
||||
<table class="form-table" role="presentation">
|
||||
<tr class="form-field form-required">
|
||||
<th scope="row"><label for="site-address"><?php _e( 'Site Address (URL)' ); ?> <span class="required">*</span></label></th>
|
||||
<th scope="row">
|
||||
<label for="site-address">
|
||||
<?php
|
||||
_e( 'Site Address (URL)' );
|
||||
echo ' ' . wp_required_field_indicator();
|
||||
?>
|
||||
</label>
|
||||
</th>
|
||||
<td>
|
||||
<?php if ( is_subdomain_install() ) { ?>
|
||||
<input name="blog[domain]" type="text" class="regular-text ltr" id="site-address" aria-describedby="site-address-desc" autocapitalize="none" autocorrect="off" required /><span class="no-break">.<?php echo preg_replace( '|^www\.|', '', get_network()->domain ); ?></span>
|
||||
|
@ -222,7 +221,14 @@ printf(
|
|||
</td>
|
||||
</tr>
|
||||
<tr class="form-field form-required">
|
||||
<th scope="row"><label for="site-title"><?php _e( 'Site Title' ); ?> <span class="required">*</span></label></th>
|
||||
<th scope="row">
|
||||
<label for="site-title">
|
||||
<?php
|
||||
_e( 'Site Title' );
|
||||
echo ' ' . wp_required_field_indicator();
|
||||
?>
|
||||
</label>
|
||||
</th>
|
||||
<td><input name="blog[title]" type="text" class="regular-text" id="site-title" required /></td>
|
||||
</tr>
|
||||
<?php
|
||||
|
@ -257,7 +263,14 @@ printf(
|
|||
</tr>
|
||||
<?php endif; // Languages. ?>
|
||||
<tr class="form-field form-required">
|
||||
<th scope="row"><label for="admin-email"><?php _e( 'Admin Email' ); ?> <span class="required">*</span></label></th>
|
||||
<th scope="row">
|
||||
<label for="admin-email">
|
||||
<?php
|
||||
_e( 'Admin Email' );
|
||||
echo ' ' . wp_required_field_indicator();
|
||||
?>
|
||||
</label>
|
||||
</th>
|
||||
<td><input name="blog[email]" type="email" class="regular-text wp-suggest-user" id="admin-email" data-autocomplete-type="search" data-autocomplete-field="user_email" aria-describedby="site-admin-email" required /></td>
|
||||
</tr>
|
||||
<tr class="form-field">
|
||||
|
|
|
@ -2354,8 +2354,9 @@ function comment_form( $args = array(), $post = null ) {
|
|||
$required_attribute = ( $html5 ? ' required' : ' required="required"' );
|
||||
$checked_attribute = ( $html5 ? ' checked' : ' checked="checked"' );
|
||||
|
||||
// Identify required fields visually.
|
||||
$required_indicator = ' <span class="required" aria-hidden="true">*</span>';
|
||||
// Identify required fields visually and create a message about the indicator.
|
||||
$required_indicator = ' ' . wp_required_field_indicator();
|
||||
$required_text = ' ' . wp_required_field_message();
|
||||
|
||||
$fields = array(
|
||||
'author' => sprintf(
|
||||
|
@ -2420,12 +2421,6 @@ function comment_form( $args = array(), $post = null ) {
|
|||
}
|
||||
}
|
||||
|
||||
$required_text = sprintf(
|
||||
/* translators: %s: Asterisk symbol (*). */
|
||||
' <span class="required-field-message" aria-hidden="true">' . __( 'Required fields are marked %s' ) . '</span>',
|
||||
trim( $required_indicator )
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters the default comment form fields.
|
||||
*
|
||||
|
|
|
@ -5021,6 +5021,38 @@ function __checked_selected_helper( $helper, $current, $echo, $type ) { // phpcs
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Assigns a visual indicator for required form fields.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @return string Indicator glyph wrapped in a `span` tag.
|
||||
*/
|
||||
function wp_required_field_indicator() {
|
||||
/* translators: Character to identify required form fields. */
|
||||
$glyph = __( '*' );
|
||||
$indicator = '<span class="required" aria-hidden="true">' . esc_html( $glyph ) . '</span>';
|
||||
|
||||
return $indicator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a message to explain required form fields.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @return string Message text and glyph wrapped in a `span` tag.
|
||||
*/
|
||||
function wp_required_field_message() {
|
||||
$message = sprintf(
|
||||
'<span class="required-field-message" aria-hidden="true">%s</span>',
|
||||
/* translators: %s: Asterisk symbol (*). */
|
||||
sprintf( __( 'Required fields are marked %s' ), wp_required_field_indicator() )
|
||||
);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default settings for heartbeat.
|
||||
*
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-alpha-53887';
|
||||
$wp_version = '6.1-alpha-53888';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue