Zum Hauptinhalt springen

Complete guide to Wordpress Plugin Development with VS-Code

Because I did not find a complete article that includes plugins and configuration, I assembled my own, after I spent some time to get a fully functional environment.

Mandatory plugins

List of plugins to be able to syntax-highlight and auto-complete php and wordpress framework code.

Lastly configure the Wordpress Stub in PHP Intelephense as described in this Github Issue. Alternativly you can include a whole wordpress directory manually as project folder.

Now you should be good to go.

Optional plugins

This is an opinionated list of helpful plugins for general software development with PHP code:

  • Composer auto-completion with All-in-One composer plugin.
  • If you use .editorconfig in your repository, this plugin parses and applies it for.
  • To lint via phpcs, use php-codesniffer. There is another plugin with more installs, but that wouldn’t work and is unmaintained since 2018. This one here works for me.

After setting up your phpcs.xml.dist with the prefered sniffs, you need phpcs discover all your installed sniffs. The most easy way is via dealerdirect/phpcodesniffer-composer-installer.

Appendix

Manual phpcs sniff discovery

Update 2023/04/25: Today was the first time I used composer suggest and stumbled across the dealerdirect/phpcodesniffer-composer-installer package, which takes care of finding all sniffs in the vendor packages. I leave the manual configuration here for completeness.

Till now I didn’t come accross any other way of doing this, but you have to configure the installed_path to point to each of the phpcs sniffs by an absolute path.

The following line works for my setup, with the four different sniffs phpcompat (incl. wp, paragonie) and wordpress code standard.

./vendor/bin/phpcs --config-set installed_paths \
$(pwd)/vendor/phpcompatibility/phpcompatibility-wp,\
$(pwd)/vendor/phpcompatibility/php-compatibility,\
$(pwd)/vendor/phpcompatibility/phpcompatibility-paragonie,\
$(pwd)/vendor/wp-coding-standards/wpcs