| | 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 | */ |
| | 8389 | function 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 | */ |
| | 8413 | function 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 | } |