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.
- 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
- Install PHP CodeSniffer (PHPCS) Locally:
composer require --dev "squizlabs/php_codesniffer:*"
This installs PHPCS in the project’s vendor
directory.
- Install WordPress Coding Standards Locally:
composer require --dev wp-coding-standards/wpcs
- 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
- 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.
- Configure Your Project’s Rules: You may want to create or modify a
phpcs.xml
orphpcs.xml.dist
file in your project directory to specify the rules you want to use. - 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!