PHPCS and WordPress: Which sniff to use?

flat screen monitor

Which WordPress sniff?

When using PHPCS for checking WordPress code, there are a number of sniffs/rulesets that you can use…

  1. WordPress-Core. This cover off the WordPress core coding standards
  2. WordPress-Docs. This one checks for WordPress inline documentation standards
  3. WordPress-Extra. This is an extended set of rules with recommended best practices, not sufficiently covered in the WordPress core coding standards. In other words, above and beyond the core standards. This also includes the WordPress-Core standards.
  4. WordPress. This is a complete set with all of the sniffs – the equivalent of WordPress-Extra and WordPress-Docs

As a developer, I’m not sure why you’d want to use anything other than the whole set, so I’d recommend using the WordPress sniffs.

Use a VIP sniff?

If you’re using the set-up that I documented, you’ll also have the VIP sniffs installed as well.

WordPress VIP are an enterprise-level hosting company, dealing with some of the biggest websites there are. As a result, they have additional requirements around tighert security and better performance.

  • WordPressVIPMinimum – for use with projects on the (older) WordPress.com VIP platform.
  • WordPress-VIP-Go – for use with projects on the (newer) VIP Go platform.

All customers have been moved off the original WordPress.com platform, so you should only really use WordPress-VIP-Go.

These rulesets contain only the rules which are considered to be “errors” and “warnings” and use rules from the WordPress Coding Standards (WPCS) project, as well as the VariableAnalysis standard. VIP have certain differences on their platform which may mean that certain things don’t work (e.g. they have a mainly read-only file system), so these sniffs will highlight this and offering up links to documentation and general solutions.

I would recommend using this sniff along with WordPress.

How to check which sniffs you have

On the command line run phpcs -i to view the sniffs that you have installed locally. This is my output…

The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, WordPress-VIP-Go, WordPressVIPMinimum, PHPCompatibility, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityWP, Modernize, NormalizedArrays, Universal, PHPCSUtils, VariableAnalysis, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra

Talk to me!

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from David Artiss

Subscribe now to keep reading and get access to the full archive.

Continue reading