#56389 closed enhancement (fixed)
Make wp_required_field_indicator and wp_required_field_message filterable
Reported by: | kebbet | Owned by: | audrasjb |
---|---|---|---|
Milestone: | 6.1 | Priority: | normal |
Severity: | normal | Version: | 6.1 |
Component: | General | Keywords: | has-patch has-unit-tests has-dev-note |
Focuses: | Cc: |
Description
This ticket adds filters for the output of wp_required_field_indicator
and wp_required_field_message
.
This is a follow up to #54394 which introduced two new function for required fields: wp_required_field_indicator
and wp_required_field_message
.
A PR was added to the original ticket.
Attachments (1)
Change History (20)
This ticket was mentioned in PR #3088 on WordPress/wordpress-develop by kebbet.
2 years ago
#1
#2
@
2 years ago
- Milestone changed from Awaiting Review to 6.1
- Owner set to audrasjb
- Status changed from new to reviewing
Thanks for opening a new ticket!
#7
@
2 years ago
- Keywords needs-unit-tests added
I need to add a comment on #23870 to check for agreement whether filtering the full markup is a better option than filtering only the glyph. And the participants on that ticket would need props here, as this would close both tickets. (I already took the translated asterisk from that ticket.)
If we do not filter the glyph on its own, we could combine the two lines, as @audrasjb suggested on PR 2982 (I had separated them specifically for the other filter):
/* translators: Character to identify required form fields. */ $indicator = '<span class="required" aria-hidden="true">' . esc_html__( '*' ) . '</span>';
Also, the wp_required_field_indicator
description could be improved, perhaps like this:
"Filters the markup for a visual indicator of required form fields."
#8
@
2 years ago
Sample functions to test these filters:
- Remove
aria-hidden
attribute, if it stays in Core (see #55717):
add_filter( 'wp_required_field_indicator', 'wptrac_remove_aria_hidden_indicator', 10, 1 ); function wptrac_remove_aria_hidden_indicator( $indicator ) { $indicator = str_replace( ' aria-hidden="true"', '', $indicator ); return $indicator; } add_filter( 'wp_required_field_message', 'wptrac_remove_aria_hidden_message', 10, 1 ); function wptrac_remove_aria_hidden_message( $message ) { $message = str_replace( ' aria-hidden="true"', '', $message ); return $message; }
- Use a non-breaking space before the indicator in the message so it does not wrap to the next line on its own.
add_filter( 'wp_required_field_message', 'wptrac_required_fields_use_nonbreaking_space', 10, 1 ); function wptrac_required_fields_use_nonbreaking_space( $message ) { $message = str_replace( ' <span class="required"', ' <span class="required"', $message ); return $message; }
#9
@
2 years ago
- Keywords needs-design-feedback added; needs-unit-tests removed
@kebbet I've added PHPUnit Tests in 56389.tests.diff for these filters (and by extension, the functions themselves). Could you add them to PR 3088?
Also, @audrasjb, since these functions weren't previously covered in the test suite, if you want me to separate the creation of these test classes into separate tickets for history, let me know, and then the tests just for these filters can be added via this ticket.
#12
@
2 years ago
- Keywords commit added
The PR gets sufficient approval and is ready to merge. @costdev, could you please review the PR and provide feedback so that it can be merged?
#13
@
2 years ago
I've reviewed the PR and it looks good to me!
Committers: Please note that once #55717 lands, the tests here will need to be updated to remove aria-hidden="true"
.
2 years ago
#14
@SergeyBiryukov In 80ffb13, the test class name was changed from TitleCase to camelCase. In Writing PHPUnit Tests - Test Classes, it says:
Test class names should reflect the filepath, with underscores replacing directory separators and TitleCase replacing camelCase. Thus, the class Tests_Comment_GetCommentClass(), which contains tests for the get_comment_class() function, is located in tests/comment/getCommentClass.php.
I understand this commit was made for consistency. Should the handbook, or the test suite, be updated?
#15
@
2 years ago
- Keywords needs-design-feedback removed
- Status changed from reviewing to accepted
Tests updated directly in the PR.
Let's ship it.
2 years ago
#17
Committed in https://core.trac.wordpress.org/changeset/54137
Introduce 3 filters to the 2 new wp_required_field_*-functions.
https://core.trac.wordpress.org/ticket/56389