Hyphens instead of Underscores in Post-type Archive Template Filenames when Post-type handle contains underscore

I’m working on implementing WordPress coding standards on a theme which has several custom post-types, each of which have underscores in their handles. The theme uses the custom post-type handle in the file-names, eg: archive-my_posttype.php for the my_posttype post-type… But WordPress coding standards require that filenames use hyphens and not underscores, ( see WordPress.Files.FileName.NotHyphenatedLowercase for … Read more

Are we allowed to use the Allman (BSD) indent style when coding WordPress plugins and themes?

I am a real fan of the Allman (BSD) coding indent style. However, when i review the top rated plugins on WordPress, i am finding them using the K&R coding indent style. Is there a requirement from WordPress.org that forces users to use the K&R indent style when developing plugins or themes? I read all … Read more

How to set up phpcs with WordPress coding standard with PHP8?

Trying to set up PHP_CodeSniffer with the WordPress Codings Standards. I’m running PHP v8.0.3 and phpcs v3.5.8. (in March 2021). WPCS is installed via git clone -b master https://github.com/WordPress/WordPress-Coding-Standards.git wpcs The installation worked, but running phpcs leads to this error: phpcs: Uncaught TypeError: vsprintf(): Argument #2 ($values) must be of type array, string given in … Read more

How Flexible are the WordPress Coding Standards for PHPCS?

In my WordPress workflow I use Gulp and have a task that runs my PHP files through PHPCS using the WordPress coding standards tests (https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards). While writing my comments.php file, I have run across the following error: Expected next thing to be an escaping function (see Codex for ‘Data Validation’), not ‘_x’ This is being … Read more

WP Coding standards – escaping the inescapable?

How do you escape these two examples? wc_price() wraps the already escaped $product_price in p and span tags with currency symbol. $product_price = $product->get_price(); <p><?php echo wc_price( esc_html( $product_price ) ); ?></p> The next one outputs the complete image with all attributes: src, srcset, alt, etc. $product_img = $product->get_image(); <?php echo $product_img; ?> 2 Answers … Read more