If a few days ago we saw how to install WordPress standards on our Ubuntu-based development server (also valid for WSL), now we are going to see the same process on our Windows 11 desktop computer (also valid for Windows 10).
Composer
Installing Composer for Windows is very easy as described at https://getcomposer.org/download/.
Simply, we download the executable and install it and it takes care of configuring the PATH to be able to run Composer from any path.
Be sure to select the “Developer mode” option to have access to the command line.
As always we check the version of Composer installed running(2.6.5 at the time of publishing this post):
composer --version
To update Composer, open a console (best with Windows Power Shell) and run the following:
composer self-update
If we have not run the console as administrator, it will tell us that it does not have write permissions, if we want to run it as administrator, we will press Y (Yes) and our version of Composer will be updated to the latest one.
Install phpcs
To install phpcs we execute in the console:
composer global require "squizlabs/php_codesniffer=*"
To see the installed configuration file, as well as the paths to the standards, we execute:
phpcs --config-show
or to view the standards:
phpcs -i
If we have standards that we no longer want to use, that we have installed in a different way (as in the first article), etc. and we want to keep only the default standards, we run:
phpcs --config-set installed_paths %USERPROFILE%\AppData\Roaming\Composer\vendor\squizlabs\php_codesniffer\src\Standards
We check again if we already have only the default standards with phpcs -i
and continue.
The following steps are identical to the Linux version.
Installing WordPress standards
To install the WordPress standards we run:
composer global config allow-plugins.dealerdirect/phpcodesniffer-composer-installer true
composer global require --dev wp-coding-standards/wpcs:"^3.0"
And again we test if the WordPress standards have been installed and are accessible from any directory and from any Windows console (phpcs -i
).
In my case I try Windows Power Shell, Command Prompt (cmd) and Git Bash console.
This will be necessary to avoid problems later in the VSC configuration.
And to update the version of the standards, we will execute:
composer global update wp-coding-standards/wpcs --with-dependencies
Installing more standards
We repeat the procedure from the previous article, to install the WooCommerce, PHP Compatibility and PHP Compatibility WP standards.
// WooCommerce Standards
composer global require --dev "woocommerce/woocommerce-sniffs"
And as we already saw, with the installation of WooCommerce standards, PHP Compatibility and PHP Compatibility WP among others are installed.
And now we can check our files from VSC or for example see if our plugin would pass the WooCommerce market validation:
phpcs --warning-severity=0 -s --ignore-annotations --extensions=php,html .