How to install PHP CodeSniffer for WordPress.com VIP

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:

  1. install PHP CodeSniffer: https://github.com/squizlabs/PHP_CodeSniffer#installation.
  2. next, install the WordPress PHP CodeSniffer rules ( WPCS ) here: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards#installation
  3. next install the VIP Coding Standards ( VIPCS ) here: https://github.com/Automattic/VIP-Coding-Standards

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:

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.

Ready to get started?

Drop us a note.

No matter where you are in the planning process, we’re happy to help, and we’re actual humans here on the other side of the form. 👋 We’re here to discuss your challenges and plans, evaluate your existing resources or a potential partner, or even make some initial recommendations. And, of course, we’re here to help any time you’re in the market for some robust WordPress awesomeness.