Configure PHP Storm for WordPress

screenshot of PHP Storm Coding Standard dropdown populated with WordPres options

PHP Storm isn’t free, the learning curve is a little steep, and configuration can be difficult. But that first time you click  ⌥ + ⌘ + L and watch all of your => line up underneath each other like little soldiers, or hover over a hook and type ⌘ + B and get whisked to the original function declaration in the WordPress Core, or generate custom doc blocks, or type forek and it generates all the syntax for a foreach loop …. ???? + ????!

Below is my attempt to walk you through the setup so that you can start leveraging this powerful IDE to build WordPress sites with ease. Here’s are the steps:

In terminal

1. Install PHP Code Sniffer globally with Composer

Assuming you already have Composer installed, run the following from the command line :

composer global require "squizlabs/php_codesniffer=*"

2. Add the path to your $PATH variable so terminal can find it

Open your .bash_profile or .zshrc file and add the following so that terminal can find the global path:

export PATH="$HOME/.composer/vendor/bin:$PATH"

$ which phpcs

check the path to see if it was successfully installed:

which should return:

$ /Users/[yourname]/.composer/vendor/bin/phpcs

3. Download the WordPress Coding Standards to a new directory (below I created an empty directory called wpcs)

$ git clone [email protected]:WordPress-Coding-Standards/WordPress-Coding-Standards.git wpcs

4. Add the WPCS to PHPCS

$ phpcs --config-set installed_paths /Users/[yourname]/wpcs

In PHP Storm

  1. Navigate to: Preferences (⌘,) > Languages & Frameworks > PHP > Frameworks
  2. Check Enable WordPress Integration
  3. Set the path to your Public folder (or whatever root directory that contains your entire WordPress installation)
screenshot of turning on WordPress Coding Standards plugin on PHP Storm

4. Click Validate + OK

Add the phpcs executable file path

  1. Navigate to: Preferences (⌘,) > Languages & Frameworks > PHP > Quality Tools > Code Sniffer

2. Click on the … to bring up the path field and add the path to your file

Screenshot of PHP Storm Code Sniffer path

3. Click Validate + OK

Choose the WordPress Coding Standards from the Coding Standard Drop-down

  1. Navigate to: Preferences (⌘,) > Editor > Inspections > PHP > Quality Tools > PHP
  2. Click/check Code Sniffer Validation
  3. Hit the refresh button in the Coding Standards drop down

4. Choose a WordPress coding standard from the drop-down

screenshot of PHP Storm Coding Standard dropdown populated with WordPres options

5. Repeat steps for Default so you have the above set-up going forward

Published
Categorized as Tutorial

Leave a comment

Your email address will not be published.