Opened 9 years ago
Closed 8 years ago
#40829 closed enhancement (fixed)
Improve wp_dropdown_languages() so it doesn't print out empty attributes
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 4.9 | Priority: | normal |
| Severity: | normal | Version: | |
| Component: | I18N | Keywords: | has-patch needs-testing |
| Focuses: | Cc: |
Description
wp_dropdown_languages() takes an array of arguments with some defaults. Among them, the arguments related to the name and id HTML attributes default to empty string.
Later on, these attributes are printed out without any check if they're empty or not:
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
The final output might print out empty name and id attributes if the related arguments are not explicitly passed: <select name="" id="">, which doesn't look right to me.
Attachments (2)
Change History (13)
#2
follow-up:
↓ 3
@
9 years ago
- Keywords needs-refresh added; 2nd-opinion removed
- Milestone changed from Awaiting Review to Future Release
- Type changed from defect (bug) to enhancement
Let's not change $args to $r, that's not really relevant for this change.
#3
in reply to:
↑ 2
@
9 years ago
Replying to ocean90:
Let's not change
$argsto$r, that's not really relevant for this change.
It will be relevant when there's a variable collision, and it's already a commonly used approach in core.
This is still a bug, because form elements cannot have empty names.
Leaving wp_dropdown_languages() as is increases the opportunity for it to introduce more problems, as this ticket discovered already.
Why not just fix this now and move onto bigger things? This should be committed as patched, not moved into the Future Release abyss.
#4
@
9 years ago
Scanning the codebase for occurrences of wp_parse_args( $args seems to me in most of the recent files, including for example class-language-pack-upgrader.php, the variable name is a bit more meaningful: $parsed_args. In old files, it's often $args or $r.
#5
@
9 years ago
- Milestone changed from Future Release to 4.9
Let's change $r to $parsed_args, seems good to me otherwise.
40829.diff proposes the following changes:
idandnametolocaleby default instead of empty, to circumvent the issue proposed here. This also promotes the use oflocalefor future usages by core and plugins.$outputstring creation to the end of the function with the other concatenation$argsreplacement to use the$rvariable approach, as per most otherwp_parse_args()usages in core. This prevents stomping the original$argsarray, in the event a filter is introduced into this function later.Tests are passing. No further changes are needed to any usages of
wp_dropdown_languages().