How to Install WordPress Coding Standards

WordPress Coding Standards

Install PHP, WooCommerce, and WordPress Coding Standards

WordPress coding standards are used to verify the coding standard of WordPress plugins and themes. If you want to publish your plugin or theme in any market, you should first set the standards and then upload your zip file for submission.

I am explaining a few steps to easily install standards on windows.

Install Composer

Download Composer-Setup.exe and run it – follow the steps and install it for all users.

Install PHP code sniffer

https://github.com/squizlabs/PHP_CodeSniffer

Open your command prompt and run this command.

composer global require "squizlabs/php_codesniffer=*"

Download WordPress Coding Standards

https://github.com/WordPress/WordPress-Coding-Standards/archive/refs/heads/develop.zip

Download the package and make move it to a safe folder. Make sure you don’t have a folder in the path that contains space(s) in the name. You will not be able to set it as a path of standards through the command prompt.

WordPress Coding Standards

Links to PHP, JavaScript, CSS, and HTML standards are given below. Keenly read them to understand the standards of WordPress. WooCommerce also used WordPress Standards and developed WooCommerce plugins according to the standard of WordPress.

Read more about WordPress Coding standards

https://github.com/WordPress/WordPress-Coding-Standards

PHP Coding Standard WordPress

The following are the themes of the standards for PHP.

  • General
  • Naming
  • Whitespace
  • Indentation
  • Formatting
  • Declare Statements, Namespace, and Import Statements
  • Object Oriented Programming

Visit the link below to read WordPress Coding Standards for PHP.

https://developer.wordpress.org/coding-standards/wordpress-coding-standards/php/

HTML Coding Standard

Visit the link below to read WordPress Coding Standards for HTML.

https://developer.wordpress.org/coding-standards/wordpress-coding-standards/html/

CSS Coding Standard

Visit the link below to read WordPress Coding Standards for CSS.

https://developer.wordpress.org/coding-standards/wordpress-coding-standards/css/

JavaScript Coding Standard

Visit the link below to read WordPress Coding Standards for JavaScript.

https://developer.wordpress.org/coding-standards/wordpress-coding-standards/javascript/

WooCommerce Code Sniffer / WooCommerce Coding Standards

https://github.com/woocommerce/woocommerce-sniffs

Install by Command.

composer global require woocommerce/woocommerce-sniffs

Or Download the package and move it to the same folder of WordPress standards.

Set path of WordPress and WooCommerce Standards in PHP code sniffer

Add Folder path to the PHP_CodeSniffer configuration:

phpcs --config-set installed_paths path to WordPress and WooCommerce coding standards

Example Command

phpcs --config-set installed_paths D:\xampp\wpcs

Run the command to check whether everything is configured successfully.

phpcs -i
WordPress Coding Standards
List of installed Standards

WordPress Standards Command for Command Prompt

phpcs --standard=wordpress D:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce

WordPress Standards Auto Fix Command for Command Prompt

phpcbf --standard=wordpress D:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce

Leave a Reply

%d bloggers like this: