Test the new WPThemeReview standards

WPThemeReview is the official Theme Review Team coding standard used for checking the themes using PHP_CodeSniffer (PHPCSPHP Code Sniffer PHP Code Sniffer, a popular tool for analyzing code quality. The WordPress Coding Standards rely on PHPCS.).

The aim of the WPThemeReview project is to automate the code analysis part of the Theme Review Process as much as possible using static code analysisStatic code analysis "...the analysis of computer software that is performed without actually executing programs, in contrast with dynamic analysis, which is analysis performed on programs while they are executing." - Wikipedia.

Release of WordPress Coding StandardsWordPress Coding Standards The Accessibility, PHP, JavaScript, CSS, HTML, etc. coding standards as published in the WordPress Coding Standards Handbook. May also refer to The collection of PHP_CodeSniffer rules (sniffs) used to format and validate PHP code developed for WordPress according to the PHP coding standards. 2.0.0

Version 2.0.0 of WordPress Coding Standards (WPCSWPCS The collection of PHP_CodeSniffer rules (sniffs) used to format and validate PHP code developed for WordPress according to the WordPress Coding Standards. May also be an acronym referring to the Accessibility, PHP, JavaScript, CSS, HTML, etc. coding standards as published in the WordPress Coding Standards Handbook.) was released two weeks ago, and it brought some changes to the WPCS ruleset. Juliette Reinders Folmer made a pull request with the changes needed for WPThemeReview to work with WPCS 2.0.0.

We need your help in testing these changes before releasing an update.

To set the WPThemeReview in your theme you’ll need Composer.

The following instructions are based on Mac, but you have detailed instructions in the contributing document.

Go to your theme folder and from the terminal run

composer require wptrt/wpthemereview:dev-develop dealerdirect/phpcodesniffer-composer-installer:^0.4.4

This will install the develop branch of the WPThemeReview standards as well as composer pluginPlugin A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory https://wordpress.org/plugins/ or can be cost-based plugin from a third-party that will register all the standards with PHPCS. After that you can run

vendor/bin/phpcs -i

You should see

The installed coding standards are PEAR, Zend, PSR2, MySource, Squiz, PSR1, PSR12, PHPCompatibility, PHPCompatibilityParagonieRandomCompat, PHPCompatibilityParagonieSodiumCompat, PHPCompatibilityWP, WordPress, WordPress-Extra, WordPress-Docs, WordPress-Core and WPThemeReview

Then just run

vendor/bin/phpcs -p . --standard=WPThemeReview

You should see something like this


WW...W.W.....W......WWW.WW.W.WW.WW.....WEEEEEEEEEEEEEEWEEEEE   60 / 1197 (5%)
EEWEEEWEEEEEEEEEWEWEEEEEEEEEEEEEEEEEEEEEEEE.EEEEEEEEEEEEEEEE  120 / 1197 (10%)
E.E..EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE  180 / 1197 (15%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE  240 / 1197 (20%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEES  300 / 1197 (25%)
EESSEESEESSSEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE  360 / 1197 (30%)
EEEEEEEEEEEEEEEEEEEEEWEEEE.EEEEEEE.EEEEEEEEEEEEEE.EEEEEEEEEE  420 / 1197 (35%)
EEEEEEEEEWEWWWEEEEWEEEE.EEEEEEEEEEEEEEEEEEEEEEEEEEEE.......W  480 / 1197 (40%)
W..WEWE.EEEEEEEEEEEEEEEEEEEE.E.EEWE..EWEEWEEEEW.EEWEWEEEEEEE  540 / 1197 (45%)
EEEEEEEEEEEEEEWEE.EWEE.EEEEE..EEEEEEEEEEEWEEEEEE.WEWEEEEE.E.  600 / 1197 (50%)
WWEEEEEEEEEE.E.EEEEEEEEE.E..EEEE..EE.E.EEE.EE.E.EEE..E.EEEEE  660 / 1197 (55%)
EEEEEEEEEE.EEEEEEE.W.EEEEEE..E.E..EEE.EEEEEWEE.EW..EWEEWWEEE  720 / 1197 (60%)
E.E..EEW..EEEEEEEEEEEEEEEEEE.EE.E.EEEEEEEEEEEEEEEEEEEEEEEEEE  780 / 1197 (65%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE.WEWE.EEEE  840 / 1197 (70%)
EE..EE.E.EE..EE...EE...E..EEE..EE.EEE.EEEEEEEE.EEE.EE.EEEEEE  900 / 1197 (75%)
EEEEEE.EEEEEEEEEEEEEEEEEWEWE..EEEE.EEEEEEE...EEE..EE.EEEEEEE  960 / 1197 (80%)
EEEWEEEEEEE.EEEE.EEWEE.EEEEEEWWWEEEEEEEEEEE.EEEEE.EEEEEEEEEE 1020 / 1197 (85%)
EEEEEEEE.EEEE.E..E.EEWEE.EE.EEEE.EEEEEEEE..EEEEEEEEEEEEEEEEE 1080 / 1197 (90%)
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE 1140 / 1197 (95%)
EEEEEEEEEEEEEEEEEEEEEEE.EE.....E.E.WEE.EEEEEEEEEEEE.EEEEE    1197 / 1197 (100%)



FILE: public_html/wp-content/themes/twentynineteen/functions.php
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 0 ERRORS AND 2 WARNINGS AFFECTING 2 LINES
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 273 | WARNING | All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '$primary_color'.
 274 | WARNING | All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found
     |         | 'twentynineteen_custom_colors_css'.
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
...

If you find any errors or problems with setup feel free to report the issue on the Github or here in the comments.

#coding-standards, #wpthemereview