PHPCS set up for just one specific WordPress project


Let’s get PHPCS set up for just one specific WordPress project. You can do this using Composer, which is a great way to manage dependencies on a per-project basis.

  1. Navigate to Your Project Directory: Open your terminal and navigate to the directory of the WordPress project you’re working on.
cd /path/to/your/project
  1. Install PHP CodeSniffer (PHPCS) Locally:
composer require --dev "squizlabs/php_codesniffer:*"

This installs PHPCS in the project’s vendor directory.

  1. Install WordPress Coding Standards Locally:
composer require --dev wp-coding-standards/wpcs
  1. Set the Installed Paths for PHPCS: You’ll need to tell PHPCS where to find the WordPress standards:
./vendor/bin/phpcs --config-set installed_paths ../../phpcsstandards/phpcsextra,../../phpcsstandards/phpcsutils,../../wp-coding-standards/wpcs
  1. Verify Your Installation: You can check if everything is set up correctly with:
./vendor/bin/phpcs -i

This should show WordPress among the available coding standards.

  1. Configure Your Project’s Rules: You may want to create or modify a phpcs.xml or phpcs.xml.dist file in your project directory to specify the rules you want to use.
  2. Run PHPCS: You can now run PHPCS on your project files with:
./vendor/bin/phpcs /path/to/your/files

By following these steps, PHPCS and the WordPress Coding Standards will only be installed for this specific project without affecting other projects on your system.

🎉 Happy coding!