Install PHP, WooCommerce, and WordPress Coding Standards
WordPress coding standards are used to verify the coding standards 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.
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 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.
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 standards 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
List Coding standards
Run the command to check whether everything is configured successfully.
phpcs -i
Commands of WordPress Coding Standards
PHPCS command for WordPress
The PHPCS (PHP CodeSniffer) command for WordPress is a valuable tool for developers working with WordPress. It’s a command-line utility that enforces coding standards and best practices within WordPress projects. By using PHPCS, developers can ensure that their WordPress themes, plugins, and custom code adhere to the WordPress Coding Standards. This helps maintain consistency, readability, and quality in WordPress development, making it easier to collaborate, identify and fix coding errors, and create secure and efficient WordPress solutions. Whether you’re a seasoned WordPress developer or just starting, the PHPCS command is an indispensable resource for producing high-quality code that aligns with WordPress standards.
phpcs --standard=wordpress D:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce
PHPCBF command for WordPress(Autofix)
The PHPCBF (PHP Code Beautifier and Fixer) command for WordPress is a powerful tool designed to streamline and enhance the quality of your WordPress code. It’s part of the PHP CodeSniffer suite, and it focuses on automatically identifying and correcting coding standard violations in your WordPress projects. By using PHPCBF, developers can ensure their code adheres to the WordPress Coding Standards with minimal manual intervention. This not only makes your code more readable and consistent but also accelerates the development process by automatically fixing common coding issues. It’s an essential tool for WordPress developers looking to maintain coding best practices and create more efficient, reliable, and standardized code within their themes, plugins, or custom WordPress projects.
phpcbf --standard=wordpress D:\xampp\htdocs\wordpress\wp-content\plugins\woocommerce
Raja Aman Ullah is a highly skilled WordPress and WooCommerce plugin developer working as a lead plugin developer. He developed numerous famous extensions including b2b, request a quote, ultimate membership, custom fields, and many others for WooCommerce that are trending on Extension Store. His products on WooCommerce have more than 100,000 active subscriptions and happy clients.
Hire me