WordPress / WordPress/WordPress-Coding-Standards
Flag echo usage errors when selected(), disabled(), checked() helpers
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 2.8k
- Forks
- 521
- Avg merge
- 5d 20h
- Merged PRs (30d)
- 1
Description
Consider:
$output .= selected( in_array( $category->slug, $selected_options ) );
This will not have the desired effect, since the 3rd argument to selected(), $echo, defaults to true.
It would be helpful if there was a sniff that looked at any instance of selected(), disabled(), checked(), etc that have an lvalue (assigned to a variable) if they do not supply the 3rd argument to the function, as such instances are surely accidental omissions of that argument.
The above PHP code could be automatically fixed up to be:
$output .= selected( in_array( $category->slug, $selected_options ), true, false );
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the PHP example and locate the WordPress Coding Standards sniffs for selected(), disabled(), and checked(). Check how an assignment is recognized and whether the third $echo argument is omitted; done means those cases are flagged and the shown false-argument correction is supported.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100