Skip to content

A comprehensive guideline to setup phpcs for a WordPress theme or plugin.

Notifications You must be signed in to change notification settings

xenioushk/phpcs_101

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PHPCS Setup

A comprehensive guideline to setup phpcs for a WordPress theme or plugin.

Requirements

You need to install the following softwares on your machine.

Steps

  1. Navigate to the project root directory.
  2. Open composer.json file and add/update the codes.
"require": {
  "php": ">=7.4|^8.0",
  "composer/installers": "^1.0.12"
},
"require-dev": {
  "wp-coding-standards/wpcs": "^3.1",
  "phpcompatibility/phpcompatibility-wp": "2.1",
  "dealerdirect/phpcodesniffer-composer-installer": "^1.0",
  "squizlabs/php_codesniffer": "^3.10"
},
"config": {
  "allow-plugins": {
    "composer/installers": true,
    "dealerdirect/phpcodesniffer-composer-installer": true,
    "johnpbloch/wordpress-core-installer": true
  }
}
  1. Run the command to install composer packages.
composer update
  1. You will now see a bin folder inside the vendor directory.

phpcs bin directory

  1. Next, open the package.json file and add this code.
"lint:php": "vendor/bin/phpcs",
"lint:php:fix": "vendor/bin/phpcbf",

Update package.json file

  1. Now, copy/download the phpcs.xml file from this link and paste it to the project root directory.

Update package.json file

  1. All done. Now, we can run this command to check the php linting errors and fix them.
npm run lint:php
npm run lint:php:fix

Output:

PHPCS linting report

Acknowledgement

About

A comprehensive guideline to setup phpcs for a WordPress theme or plugin.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published