Technote

Development workflow Intro

The real payoff of WordPress coding standards

The value of a standard is not tidier code — it is that formatting stops being discussed in review. For that, the tooling has to raise it rather than a colleague, and the setup takes an afternoon.

Propose adopting a coding standard and the first reply is usually “but it works fine as it is”. Which is true — conforming to a standard does not make code faster, and bugs do not evaporate. The payoff is somewhere else entirely: formatting stops being discussed in review.

The gain is attention, not tidiness

Review in a repository without a standard goes like this. “Your indentation differs here.” “I would put that brace on the next line.” “Shall we agree a naming rule?” All of it is an exchange of preferences, and even when settled it restarts in the next file.

Worse, that conversation spends attention first. Nobody reads code with full concentration for very long, and if the opening minutes go on whitespace and braces, less is left for what actually matters: does this change match the intent, is there an edge case nobody handled.

That is where the real value sits. Which convention wins is unimportant; that one has been chosen is everything. And whatever has been chosen should not be raised by a person — when the tooling raises it, nobody’s attention is spent at all.

A standard changes not how the code looks but what review is about

What the standard actually settles

The WordPress coding standards cover PHP, HTML, CSS and JavaScript; in daily work it is the PHP rules that fire. They fall into three groups.

Formatting — tabs for indentation, spaces inside parentheses, short array syntax. This group is auto-fixable, so people barely touch it.

Naming — lowercase underscores for functions and variables, capitalised class names, file naming. Project prefix rules are usually layered on here.

Safety — this group is the real reason to adopt the standard. The ruleset flags missing output escaping, unsanitised input, direct $wpdb queries without prepare(), and missing nonce verification. If the formatting rules made this look like a matter of taste, this group settles the question.

Let the tooling enforce it

Setup is short. Install the ruleset as a development dependency and commit a configuration file.

composer require --dev wp-coding-standards/wpcs 
    dealerdirect/phpcodesniffer-composer-installer

vendor/bin/phpcs   # check
vendor/bin/phpcbf  # fix automatically

Committing the ruleset file (phpcs.xml.dist) is the part people skip. If the configuration exists only in individual editors, everyone checks against slightly different rules — and then you do not have a standard, you have several opinions about one.

<?xml version="1.0"?>
<ruleset name="Acme">
    <file>.</file>
    <exclude-pattern>vendor/*</exclude-pattern>
    <exclude-pattern>node_modules/*</exclude-pattern>

    <rule ref="WordPress"/>

    <config name="minimum_wp_version" value="6.0"/>
    <rule ref="WordPress.WP.I18n">
        <properties>
            <property name="text_domain" type="array" value="acme"/>
        </properties>
    </rule>
</ruleset>

Then wire it into three places. In the editor it shows up as you type; in a commit hook it checks only the changed files and stays fast; in CI it becomes the gate nobody can walk around. All three is ideal, but if you pick one, pick CI — the others are personal configuration and personal configuration goes missing.

Three places to run the check — by review time, formatting is no longer a topic

Adopting it without a giant rewrite

Switch the standard on over an existing codebase and you get thousands of warnings. Trying to clear them all produces one enormous change that cannot be reviewed, and mixing it with behaviour changes turns it into an incident.

The practical order runs like this. Apply the check to new code only at first — configure CI to inspect changed files and you can start without touching anything historical. Next, take just the auto-fixable formatting rules and clean one directory at a time in pure formatting commits, never mixed with behaviour. Finally, turn the remaining safety warnings into a list and work through it individually, because those may be genuine defects rather than style and should not be bulk-processed.

When a rule genuinely needs an exception, record the reason with it. Suppression comments without justification multiply, and once they do the check stops being believed.

A good companion is a PHP compatibility check: declare the lowest version you support and newer syntax gets caught before deployment rather than after.

Wiring these checks into CI is covered in the From local to production series, and related writing sits in the development workflow archive. If the accumulated code needs its quality and its vulnerabilities addressed together, PHP source clean-up is part of our optimization program.

More on this topic

All technotes

Development workflow Intro

Decide the question before you open the dashboard

A dashboard opened without a question produces observations, not decisions. Writing one sentence before you open it changes the whole meeting.

Product planners 7 min read

Development workflow Intro

The real problem behind “just add this feature”

A request has already been translated once. The person asking turned their need into a solution before they spoke — and building that solution usually solves the wrong…

Product planners 7 min read

Development workflow Intro

Scope a redesign by writing down what you will not do

A redesign with no completion condition never completes. "While we are at it" is how schedules die, and the document that stops it is not a to-do list…

Product planners 7 min read

₩270,000 · Join the program