nirab

vsCode Configuration for WordPress Plugin

Dec 17, 2022
#vsCode

First of all you need to install wpcs dependencies on your plugin via composer :

composer require --dev wp-coding-standards/wpcs:dev-develop

After install this package, you’ll get access these two types of commands :

# check php coding standard releted issues

./vendor/bin/phpcs
# fix coding standard automatically

./vendor/bin/phpcbf

I recommend to register these commands with composer scripts.

"scripts": {
	"phpcs": "\"vendor/bin/phpcs\"",
	"phpcbf": "\"vendor/bin/phpcbf\"",
	"sniffs": "\"vendor/bin/phpcs\" -e",
}

then you can easily access phpcs commands via composer:

composer phpcs
composer phpcbf
composer sniffs

Extensions

Some vsCode extensions, I always use :

PHP-Intelephense I recommend PHP Intelephense for PHP built-in functions completion, code completion (IntelliSense), go to definition support and many more.

Phpcs

phpcs extension allow us to display phpcs related issues without running phpcs commands every time & also fix coding styles after save file.

To enable WordPress coding standards:

"phpsab.standard": "WordPress",

It’s automatically configure setup from your root project composer.json.

But what happen if you want to develop something like WooCommerce Extension OR any other plugin based plugin !!

You need to open wordpress plugins directory instead of opening single plugin directory. vsCode explorer

Then you can get better code completion (IntelliSense) support.

But the phpcs extension doesn’t work, you need to configure locally in the plugins directory. So, create new folder called .vscode under the project root and create settings.json file here.

Inside settings.json :

{
  "phpsab.executablePathCS": "./subscription-pro/vendor/bin/phpcs",
  "phpsab.executablePathCBF": "./subscription-pro/vendor/bin/phpcbf",
  "phpsab.standard": "WordPress",
  "[php]": {
    "editor.defaultFormatter": "valeryanm.vscode-phpsab"
  }
}

Now, you can see phpcs working fine.

vscode phpcs

The last extension is WordPress Hooks IntelliSense, which will provide better autocompletion for hooks.

wordpress intellisense

Thanks.


me

Istiaq Nirab

Full stack web developer

I’m a WordPress Plugin developer & have some experienced with WooCommerce . Last couple of years, I developed 10+ WooCommerce extensions & also did some custom solutions . I'm ready for served any WordPress & WooCommerce related custom solutions.

Follow me on twitter