Howto Setup PhpStorm to Work on WordPress Plugins (and Themes)

PhpStorm is the best PHP IDE available and you should use it. If you don’t agree stop reading. Did you stop reading? No? Good, then you aren’t a dumbass let’s get started.

This tutorial explains how to setup PhpStorm to work on WordPress Plugins (and Themes).

Target audience: Intermediate to advanced.

UPDATE (2014-03-21): PhpStorm 8 (and up) supports WordPress development out of the box. Check it out!

This tutorial will not show you how to use PhpStorm. I assume you are already using PhpStorm or want to learn and will do so on your own. This tutorial will not show you how to develop for WordPress. Yes, WP sucks and is ass-backwards PHP. Or yes, WP is amazing and powers ~20% of the web. For whatever reasons, you are here for this info.

Benefits of this type setup:

  • Automatic code completion, code navigation, PhpStorm’s kitchen sink.
  • Ability to mix version control systems (Git, SVN, Perforce, CVS, …)  and sources (GitHub, SourceForge, Codebase, core.svn.wordpress.org, … )
  • Work on multiple plugins (and themes) at the same time for the same project.

I’m a developer at PressBooks.com. This is my project setup:

wordpress-and-phpstorm-project

This structure makes up the bulk of PressBooks dot com, that is:

  • WordPress 3.5.x (Subversion)
  • PressBooks (GitHub)
  • The front page of PressBooks dot com (a private theme, hosted at Codebase)
  • Internal stats dashboard (a private plugin, hosted at Codebase)

Prerequisites

  • LAMP on localhost or LAMP on VM with mapped folders. (If this doesn’t mean anything to you then stop reading and come back when it does, young padawan)
  • PhpStorm -> Quick Start -> Open Directory
  • PhpStorm -> File -> Settings

Directories

wordpress-and-phpstorm-directories-1

Under Project Settings, select Directories. Add each content root that makes up your WordPress project.

Deployment

wordpress-and-phpstorm-deployment-1

Under Project Settings, select Deployment. Click the green +. Create a deployment profile of type “Local or Mounted Folder”. I named mine: TextoPress. Rename accordingly. Remember this renaming for the Install section that will come later. Select the Connection tab. Change “Folder” to: the root path of your WordPress site. Change “Web server root URL” to: the root URL of your WordPress site.

wordpress-and-phpstorm-deployment-2Select the Mappings tab.

  • Map WordPress to: /
  • Map Plugins to: wp-content/plugins/__PLUGIN_NAME__
  • Map Themes to : wp-content/themes/__THEME_NAME__

Replace __PLUGIN_NAME__ and __THEME_NAME__ accordingly. Click on the above screenshot and squint for more details.

wordpress-and-phpstorm-deployment-3Under Project Settings, select Deployment -> Options. Change “Upload changed files automatically to the default server” to: Always. Change “Upload external changes” to: true.

Version Control

wordpress-and-phpstorm-version-control-1

Under Project Settings, select Version Control. Add your VCS repositories.

Install

Apply changes. Right click on your project. Select “Upload to TextoPress” (Don’t see TextoPress? Exactly. Re-read the Deployment section above…)  Navigate to your web server root URL. Install WordPress using the Famous 5-Minute Install. Eventually:

wordpress-and-phpstorm-localhost-url

Remember:

  • You are editing a copy of the code, not the deployed code. If something seems weird always start by doing “Upload to TextoPress” which from here on in will be known as “Did you plug it in?”
  • You can add and remove plugins (and themes) as you feel like. Rinse and repeat the instructions above until you get the hang of it.

Code is poetry. Bad, wince-worthy poetry.

4 thoughts on “Howto Setup PhpStorm to Work on WordPress Plugins (and Themes)

  1. Tyler Style

    Always nice to see PhpStorm tutorials out there, it’s an awesome IDE. And WP being as popular as it is, I’m sure people trying to get into WP dev will find this helpful. One of the nice things about PhpStorm is also it’s built in debugging tools for both PHP and JS. I’ve found that some people find it difficult to get PHP debugging working, so I’ve created an xdebug based tutorial for setting up debugging that your readers may find of interest.

    Reply
  2. Dean jansen

    Thanks for the great post.
    I really love PHP, WordPress and PhpStorm. These are the three things i see, read, eat , hear and live with every day.

    Cant wait to see what other blog post you will be making soon.

    Reply

Leave a Reply to Dean jansen Cancel reply

Your email address will not be published. Required fields are marked *