Install WordPress Codding Standard PHPCS PHPCBF in UBUNTU

To install WordPress coding standards and PHP_CodeSniffer (PHPCS) along with PHP Code Beautifier and Fixer (PHPCBF) on Ubuntu, you can follow these steps:

  1. Install Composer:
    WordPress Coding Standards can be installed using Composer, so you need to install Composer first. Run the following commands in your terminal:
   curl -sS | sudo php -- --install-dir=/usr/local/bin --filename=composer
  1. Install PHPCS:
    Use Composer to install PHPCS globally:
   composer global require squizlabs/php_codesniffer

Ensure that Composer’s global bin directory is in your system’s PATH. You can add it to your ~/.bashrc or ~/.zshrc file:

   export PATH="$PATH:$HOME/.composer/vendor/bin"

Then, refresh your shell:

   source ~/.bashrc

Or for zsh:

   source ~/.zshrc
  1. Install WordPress Coding Standards:
    Install the WordPress coding standards by cloning the repository:
   git clone -b master ~/.composer/vendor/wp-coding-standards

After cloning, make sure to install the dependencies:

   composer install -d ~/.composer/vendor/wp-coding-standards
  1. Configure PHPCS to Use WordPress Coding Standards:
    Run the following command to let PHPCS know about the installed WordPress coding standards:
   phpcs --config-set installed_paths ~/.composer/vendor/wp-coding-standards
  1. Verify Installation:
    You can verify the installation by running:
   phpcs -i

This should list the installed coding standards, including WordPress.

  1. Install PHPCBF (PHP Code Beautifier and Fixer):
    PHPCBF is included with PHPCS, so if you’ve followed the above steps, you should already have it. You can verify by running:
   phpcbf -h

This should display help information for PHPCBF.

Now you have WordPress coding standards and PHPCS with PHPCBF installed on your Ubuntu system. You can use these tools to ensure your PHP code follows the WordPress coding standards.

Leave a comment

Your email address will not be published. Required fields are marked *