Did you know that you could get much of the feedback given by the VIP team shown to you in real-time, as you code?
PHP CodeSniffer (aka PHPCS) is a tool that will help you write VIP approved code by ensuring it meets VIP coding standards. Many IDEs and text editors (e.g. PHPStorm, Sublime Text, Atom and Vim) have packages which will highlight any code which departs from VIP coding standards, or which has security or performance issues. Running this tool in your development environment or code editor allows you to fix the errors as you code, helping you develop to VIP best practices, and saving time during review.
To install PHP CodeSniffer:
- install PHP CodeSniffer: https://github.com/squizlabs/PHP_CodeSniffer#installation.
- next, install the WordPress PHP CodeSniffer rules ( WPCS ) here: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation
- next install the VIP Coding Standards ( VIPCS ) here: https://github.com/Automattic/VIP-Coding-Standards
Note: The current
WordPress-VIP-Go rulesets are built on top of the
1.* branch of the
WordPress-Coding-Standards. For a fresh install, please checkout the
1.2.1 branch to ensure compatibility (in your /wpcs installation folder run:
git checkout -b version1.2.1 1.2.1). Using WPCS
2.* of the
WordPress-Coding-Standards will result in an error message such as the following, however an upcoming VIPCS 2.0 release will add compatibility with WPCS
Fatal error: require_once(): Failed opening required '/tmp/wpcs/WordPress/PHPCSAliases.php'
When working on a site on the WordPress.com platform, you should make use of the
WordPressVIPMinimum ruleset, which is used for automatic code scanning in the Deploy Queue. Issues flagged by these rules will be flagged on deploy and in code review.
When working on a VIP Go site, you should make use of the
WordPress-VIP-Go ruleset, which is used in CI and code review on VIP Go sites and git repos.
Note: Do not use the
WordPress-VIP ruleset that comes with WPCS, it is not used by VIP, and has been deprecated in preparation for removal by the WP Coding standards project. Use the VIP Coding standards instead.
You can then integrate PHP CodeSniffer inside your favourite IDE, we have examples for a few popular ones:
- Sublime Text:
- Atom editor:
It’s also possible to run PHP CodeSniffer in your Continuous Integration build process, e.g. via Travis or Circle CI, which allows you to see issues reported against any pull requests and to receive reports of issues via email and other channels. If you’d like us to configure the rules to run on your VIP Go GitHub repository, then please let us know and we’ll be happy to set this up for you.
When submitting your code to VIP for the initial theme we expect the code to not trigger any PHP CodeSniffer blockers and as few warnings as possible. We also have a list of things that we look for, not all of which are picked up by PHPCS, you can find those here. When working on a codebase on the WordPress.com platform, we expect the code to pass the WordPress.com VIP minimum standard.