WordPress / WordPress/WordPress-Coding-Standards

Flag echo usage errors when selected(), disabled(), checked() helpers

Open
#346 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Component: Extra Focus: Code analysis Type: Enhancement
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.