As a WordPress developer managing multiple plugins, maintaining consistent coding standards is critical. Recently, I went through a complete overhaul of my PHPCS setup on Windows while using VSCode (because the recent WPCS update broke it). This post walks through my journey, the pitfalls, and the working configuration that allows global WordPress coding standard enforcement across hundreds of plugins.
Background
I wanted:
- A single global setup of PHPCS + WPCS, avoiding separate
phpcs.xmlfiles for each plugin. - Compatibility with the PHPCSAB VSCode extension by Samuel Hilson.
- No missing-sniff errors like
Universal.NamingConventions.NoReservedKeywordParameterNames. - Support for Windows, PHPCS 3.x, and WordPress Coding Standards 3.x.
Step 1: Cleaning Up Old Installations
My initial setup was broken:
- PHPCS 4.x installed via Composer globally.
- WPCS updated to latest 4.x, referencing Universal/PHPCSUtils sniffs.
- PHPCSAB only supports PHPCS 3.x, causing fatal execution errors.
To clean everything up on Windows:
composer global remove squizlabs/php_codesniffer
composer global remove wp-coding-standards/wpcs
Note: Some dependencies may require additional
composer global removecommands. The key is to remove all PHPCS/WPCS artifacts to start fresh.
Step 2: Installing Compatible Versions
PHPCSAB only supports PHPCS 3.x, so we need to downgrade WPCS and PHPCS:
- Install PHPCS 3.13.5 globally:
composer global require "squizlabs/php_codesniffer:^3.13.5"
- Install WPCS 3.x globally:
composer global require "wp-coding-standards/wpcs:^3.0"
- Verify installations:
phpcs --version
# PHP_CodeSniffer version 3.13.5 (stable) by Squiz and PHPCSStandards
phpcs -i
# The installed coding standards are:
# PEAR, PSR1, PSR2, PSR12, Squiz, Zend, Modernize, NormalizedArrays, Universal, PHPCSUtils, WordPress, WordPress-Core, WordPress-Docs, WordPress-Extra
The presence of Universal and PHPCSUtils is necessary because older WPCS still references some of these internal sniffs.
Step 3: Configuring VSCode
PHPCSAB extension requires explicit paths for Windows:
- Open
settings.jsonin VSCode. - Set the following:
{
"phpsab.standard": "WordPress",
"phpsab.snifferEnable": true,
"phpsab.executablePathCS": "C:/Users/Ciprian/AppData/Roaming/Composer/vendor/bin/phpcs.bat",
"phpsab.executablePathCBF": "C:/Users/Ciprian/AppData/Roaming/Composer/vendor/bin/phpcbf.bat",
"phpsab.snifferShowSources": true
}
Key points:
- Use
phpcs.batandphpcbf.batfor Windows.- Do not point to PHPCS 4.x. Only 3.x works reliably with PHPCSAB.
phpsab.standardcan just be"WordPress". No global XML is required unless you want custom rules.
- Reload VSCode:
Ctrl+Shift+P → Developer: Reload Window. - Save a PHP file — it should lint without any Universal sniff errors.
Step 4: Optional Global Ruleset
If you want to override minor rules globally (indentation, short arrays, etc.), create a global phpcs.xml:
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards">
<description>Global ruleset for WordPress plugins</description>
<file>.</file>
<!-- Exclude common paths -->
<exclude-pattern>/vendor/</exclude-pattern>
<exclude-pattern>/assets/*.js</exclude-pattern>
<!-- Base WordPress-Core standard -->
<rule ref="WordPress-Core">
<exclude name="Generic.WhiteSpace.DisallowSpaceIndent"/>
<exclude name="Generic.Arrays.DisallowShortArraySyntax.Found"/>
</rule>
<!-- Override indentation -->
<rule ref="Generic.WhiteSpace.ScopeIndent">
<properties>
<property name="indent" value="4"/>
<property name="tabIndent" value="false"/>
</properties>
</rule>
<!-- Allow short arrays -->
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
</ruleset>
- Place it somewhere like:
C:/_work/_github.com/WordPress-Coding-Standards/phpcs.xml. - PHPCSAB 3.x sometimes ignores it, so this is optional. For 100+ plugins, the default WordPress standard is usually enough.
Step 5: Result
After this setup:
- All plugins are checked against the same WordPress coding standard.
- No missing-sniff errors like:
Universal.NamingConventions.NoReservedKeywordParameterNames
Universal.WhiteSpace.CommaSpacing
- Works on Windows with VSCode PHPCSAB extension.
- Supports automatic fixing using
phpcbf.
✅ Key Lessons
- PHPCSAB does not support PHPCS 4.x — always stick to 3.x.
- WPCS 4.x is incompatible with PHPCSAB 3.x — downgrade WPCS to 3.x.
- Universal/PHPCSUtils sniffs are only needed by WPCS ≥3.1. If you downgrade, they become compatible.
- Global
phpcs.xmlis optional; the default WordPress standard suffices for most cases. - On Windows, always use the
.batexecutables for PHPCS/PHPCBF.
This setup ensures a single, global, working WordPress coding standard environment across all your plugins, without touching each plugin’s folder, and fully compatible with PHPCSAB in VSCode.