How we use PhpStorm for WordPress Development

PhpStorm WordPress Development

The majority of the Delicious Brains team use PhpStorm (everyone except Brad!), the PHP IDE from JetBrains, as their go-to code editor, development environment, and all-round PHP best friend.

Many people (like Brad!) swear by using a lean and fast code editor like Sublime Text, and would find PhpStorm much slower, larger and possibly daunting to use. However, as an integrated development environment, PhpStorm offers so much more than just editing code.

In this article I will walk you through some the features that make it great for WordPress development and show you why I, and many others, love it.

WordPress Integration

As of version 8.0, PhpStorm introduced some very neat WordPress integration which makes using PhpStorm for WordPress plugin, theme, and site development even easier. A complete rundown of the new WP features can be found here.

PhpStorm now recognizes a WordPress related project and will ask you to point it in the direction of your installation path. It will also check to see if you want to add the installation to the PHP Include paths:

WordPress Include Path

This will enable the IDE to fully understand the WordPress codebase giving you some excellent benefits. If your wp-content directory is outside of the installation path, you may want to also add that as an extra ‘included path’, to allow indexing of plugin and theme files.

Hooks Support

PhpStorm’s indexing of the WP codebase really supercharges the use of action and filter hooks. This is probably my favourite new feature and it comes in a number of parts.

Navigation to a Hook’s Callback

Do you find yourself copying the callback function name of a hook and using it to find the function declaration in your codebase? No more my friend, no more. Simply CMD+Click (Ctrl+Click on Windows/Linux) on the callback::

Hook callback navigation

Navigation to Hook Invocation

Have you ever hooked a function to a WordPress core action or filter and wondered where that code will get executed? Previously that meant doing another search of the codebase, but now just click on Hook Invocation in the left gutter next to the hook, et voilà:

Hook invocation navigation

Code Completion of Hooks

There are so many action and filter hooks in the WordPress codebase that I find myself frequently checking the Codex for the correct naming. This is now taken care of with the new code completion of action and filter names.

If your wp-content directory is in a different location to the WordPress core files, you can add it as an extra include path so that hooks and filters for plugins and themes are indexed also:

Hook name autocomplete

Search on WordPress.org

Talking of the Codex: Have you ever wanted to look at the documentation for a WordPress function? Now this is super simple by highlighting the function and selecting ‘Search on WordPress.org’ from the content menu:

Hook WordPress search

Searching for where a hook is registered in WordPress? You can do this quickly within PhpStorm using ‘Navigate to Symbol’. Simply use CMD-ALT-O (Ctrl+Alt+Shift+N on Windows/Linux) and enter the name of the hook to find:

Hook navigate

Code Style

Here at Delicious Brains we are big on developing with the WordPress coding standards in mind, and the next couple of PhpStorm features make this much easier to integrate into our development workflow.

PhpStorm allows you to define coding styles for the languages you are developing with. It now comes with a WordPress-specific style that helps you automatically format your code to the coding standards (check out ‘Code > Reformat Code’).

We have forked the style with a few tweaks of our own, which you can find here. Feel free to use and let us know if you find any issues.

PHP Code Sniffer

Code styles are great for formatting code to standards, but the standards are more than just formatting, as they define rules about how the code should be written. PhpStorm allows you to integrate easily with PHP Code Sniffer to detect any issues with your code against the WordPress coding standards, defined as by the WordPress PHP Sniffer rules.

An installation guide for both PHP Code Sniffer and the WordPress rules can be found here.

Code sniffing is about prevention instead of cure, and the integration in the PhpStorm editor alerting you to issues is extremely helpful. Once you have it all installed, you will instantly start to receive feedback on any issues in your code:

PHP Sniffer

Development Tools

PhpStorm is stacked with lots of non-WordPress specific features that are great for modern development practices, but there are too many to mention here. Let me take you through some of my favourites.

Xdebug

I can’t bring myself to remember a time when I debugged PHP without using Xdebug. It is the debugging and profiling extension for PHP, that allows you to literally step through your code as it executes to troubleshoot code, watch values, evaluate expressions, and much more. PhpStorm integrates seamlessly with Xdebug with minimal installation, giving you so much more insight than var_dump.

Once you have set a breakpoint, and your code has hit that point, you can really take a second and look under the hood. You can expand objects and arrays, view the stacktrace, and in PhpStorm 9.0 there is a lovely tooltip hover detail, which evaluates expression inline. Take a look at my quick demo of troubleshooting code with Xdebug:

Profiler

Xdebug also includes a profiling tool which is useful for debugging performance of plugins, applications and processes. Although it is bundled with Xdebug, there are a few further steps to enable it with PhpStorm.

Once installed and turned on, you can run the process you want to profile and it will start capturing data, in the format cachegrind.out.%p as defined in your php.ini. You can then open this capture in PhpStorm for analysis via ‘Tools > Analyze Xdebug Profiler Snapshot’. You will see something like the following, where you can view the execution stats of each function, sort functions by time taken and calls made, as well as drilling down into the call stack for the functions:

Profiler

VCS

Although I can use Git and SVN in the command line, I like to use the VCS integration in PhpStorm as it stops me from moving between the terminal or another program. The integration is pretty slick: auto detecting VCS roots in your project, presenting a powerful file diff and merge UI, as well as displaying the version history of selections or whole files.

Since we have started to regularly contribute to WordPress core using SVN, I have found its ‘Apply’ and ‘Create’ patch features an invaluable timesaver. Simply select a patch file in your project and choose ‘Apply Patch’ from the context menu. To create a patch from your changes, go to ‘VCS > Create Patch’, or for specific files select the file(s) in the ‘Local Changes’ tab of the ‘Version Control’ panel, and choose ‘Create Patch’:

SVN patches

GitHub

If your project has Git repositories registered with remotes that are hosted on GitHub, PhpStorm gives you a couple of really nice features. You can actually create a ‘Pull Request’ from inside the IDE. Pretty handy right? Once you have committed some code to a branch, go to ‘VCS > Git > Create Pull Request’:

GitHub pull request

If you develop using the forking flow, or you contribute to open source repositories on GitHub, you will know what a hassle it is to keep your fork up to date with the master repo. PhpStorm handles this all for you, including adding an ‘upstream’ remote to your checked out fork. Go to ‘VCS > Git > Rebase My GitHub Fork’. Check out my quick demonstration video below:

If you are a PhpStorm user then I hope you found something new and useful here. If not, then perhaps it convinced you to take a look?

Over at Laracasts there is a great free series of videos on how to be awesome in PhpStorm which, although geared towards Laravel at times, is an excellent resource for developers using PhpStorm.

Let me know what your favourite features are and if I missed any you think are worth a mention.

About the Author

Iain Poulson

Iain is a WordPress and PHP developer from England. He builds free and premium plugins, as well as occasionally blogging about WordPress. Moonlights as a PhpStorm evangelist.

  • PhpStorm is definitely a great tool. I have been using it for almost a year now and this, along with your Migrate DB Plugin and Gravity Forms are secret weapons that make me a lot more productive!

    Best part that I love is that it includes all the WebStorm features and for someone like me(full stack developer), this is the perfect IDE.

    I agree that while it is slower to start, it has so many features compared to Sublime Text or any other editor that it more than makes it up.

    This was a great post and I got to learn about PHP profiling (I use XDebug regularly, never tried profiling). Will try it! Keep up great work.

  • Kris

    I’ve tried PhpStorm and used it for about a year and a half, but I stick to Sublime. I found Storm (any IntelliJ IDE, really) excruciatingly slow. A single WP theme project open, not even the whole WP installation, and it slowed to a crawl. I was always waiting for Storm to catch up with what I was typing. i7 w/ 32 GB RAM in Win7/8/10, and Linux. Storm has some useful features, but I’d take performance and reliability over fluff featureset anyday.

    • Can’t say I’ve ever noticed performance issues to that extent. There is always a lag whilst the project is indexing initially but generally any tiny loss of speed in the editor is acceptable to me, when I gain the rest of the features.

  • Andrew Cato

    Install the Key Promoter plugin – if you do an action with your mouse that has a keyboard shortcut associated with it, it’ll prompt you to use the keyboard shortcut instead. Also, if you commonly do a task that PhpStorm doesn’t have a keyboard shortcut for, it’ll prompt you to create one.

  • Jon

    I’ve tried to swtich from ST>PHPStorm a few time but 15 minutes in give up and go back to ST to get work done. It seems cool and more powerful, and only a little slower. The issue is I just don’t have time to learn to use… if someone had a quick study guide/course to switch from ST>PHPStorm I’d take it, but my ST is so personalized I’m not sure how that’d work.

    • I tried to switch to PHPStorm from ST a few times and had the same problems – ST is faster, it was perfectly customized to my liking, and I had the muscle memory for all of the shortcuts, completions, command pallet, etc.

      I was finally able to make the switch after joining the team here, most of whom used PHPStorm, so I just sort of decided that I needed to be on it as well. Really the only way that I was able to switch was by forcing myself to by removing ST from my workstation temporarily. I was slower with PHPStorm at first, but as I used it I learned how to customize it, gained the muscle memory, and learned all of the things it does much better than ST.

      I’ve since reinstalled ST, and use it often as a scratchpad or for searching through library code as it’s still faster than PHPStorm and nice to do that sort of stuff in a different app.

      Laracasts has a great set of videos about using/customizing PHPStorm as well: https://laracasts.com/series/how-to-be-awesome-in-phpstorm

      • Jon

        Thanks, I’ll check out those Laracasts.

      • The Laracasts series is definitely worth a watch when making the switch from ST.

    • Jon, you don’t have the time to save time? Every day you don’t use PHPStorm, you are costing yourself time. Spending time to learn it will be an investment that pays back massively.

      15 minutes is not enough to make a change. PHPStorm is an IDE. It’s not meant to take 15 minutes to learn.

  • guy

    I also find the learning curve for PHPStorm to be incredibly steep, and although I can see how powerful it is, simply haven’t had time to get to grips with it.

    Also, all my dev sites are hosted on a local network server, or hosted in Digital Ocean, and phpStorm only allows one to work on a local disk copy, + the Live Edit option is very slow and buggy.

    I’d love to understand how to use phpStorm properly, but am so comfortable with Sublime just can’t seem to make the switch.

    • Paul

      You shouldn’t edit files directly on your live server anyway. But there’s a new feature called remote edit: http://blog.jetbrains.com/phpstorm/2015/04/remote-edit-in-phpstorm-9-eap/

      • guy

        Well.. I don’t directly edit files on live production sites as I mentioned before, but my development sites tend to exist in VM’s on a local network server, and the stages in DO. I have no worry with editing the files on these dev servers directly.

        Remote Edit has been available for quite a while, but it doesn’t work all that well in my experience. Very slow.

        Since most of my work is actually with CSS (and SASS), I prefer to use Sublime and the LiveStyle extension for Chrome. I have been using PrePros for compiling.

        This is not actually live editing either, it is real-time remote editing without any requirement to save the files to the remote server. It is simply a mapped file hooked into Chrome Dev Tools, and I can version control my files before committing live. In fact with the new LiveStyle Alpha Chrome Dev doesn’t even need to be open, and the pre-processing aspect of it is coming along very well too.

        You will see from the blogs that this aspect of phpStorm has been long lamented and asked for improvement, but I think the name says it all PHPStorm, not CSSstorm..

        It still irks me that phpStorm is only possible to use with locally stored files, meaning my central file storage on the network server, which is only a few feet away from my desktop machines, can’t be used with phpStorm.

        I guess I need to also start making more use of Git so that I can just sync the files that way instead of hosting a lot of them in a network store.

        This post has made me want to revisit phpStorm though since I have begun to work more with php, so I will visit the Laracast tuts to see if that helps get me over the hump and become more comfortable with the IDE.

        • I can see how shifting editor and workflow together can be a pain, but working on local files in the long run is a good move to make.

          • guy

            I think the choice of editor is still a matter of using the best tool for the job, and I can see there is very little in the world that measures up to PHPStorm for PHP.. For front end devs like myself though, I am still struggling to see what the benefit is really over switching..

            Regarding working on local files, can you offer more insight on why you think this is better than being able to edit files on an internal server?

            I don’t mean the Website server, but a network drive?

            If I have 3 or 4 or 50 employees, and they rely on the network server to store files, then it seems odd that they cannot use an application to work on those files?

            Each person has their own folder, so it is not like they are at risk of working on the wrong file, and it is all version controlled anyway.

            I’m also very familiar with the reasons offered by JetBrains regarding the speed problems when editing PHP over a network connection, even if it is a high speed cable, but to play devil’s advocate, isn’t this more an indication that their software is in need of improvement?

            I’d love to hear from others regarding this.. Sublime doesn’t seem to suffer from the speed issues when accessing a network drive, so I’m genuinely curious?

  • I agree that it is a really great IDE, but WordPress development is not all about PHP. There is CSS too. I am a Full Stack Developer, but I came from a front-end background to this, and there is so much more Sublime Text can do, when it comes to CSS/Front-end stuff.

    And then there is the reason which @jb510:disqus mentioned. I just don’t have time to learn it, and I switch back to ST to get things done. Though I am trying to shift my plugin development workflow to PhpStorm.

    BTW all the stuff you mentioned above can be done with Sublime Text, even the hook navigation via CodeIntel.

    • smutek

      I’m curious, what sorts of CSS/Front-end stuff can you do with Sublime Text that you wouldn’t be able to do with PHPStorm?

      Believe it or not, PHPStorm isn’t all about PHP either (well, mostly it is, but..) it’s more than capable and handles front end workflow very well.

      It has built in compilers for sass, scss, and less but it also has a built in terminal so I run my gulp tasks right inside the IDE.

      It also supports Jade, YAML, Stylus, Compass, Handlebars and Mustache. All sorts of JavaScript stuff as well. Emmet/Zen Coding is built in.

      You can even set PHPStorm to FTP your files to your staging server at the same time you commit them to source control – which is super handy if you’re the only one working on a project. Literally, do some work, press control + v, press enter, type out your commit message and press enter again and you’ve just committed files to VC and pushed them to the server.

      Also, the jump to function definition trick that Iain mentioned earlier? You can use that on Sass variables, functions, and mixins as well! If you find yourself wondering what in the hell $padding-default-small is, or @include obscure($mixin) is, you just drop your cursor over the name of the variable, press command + down arrow (or control click) and PHPStorm takes you right to the definition.

      Press command + e + enter and you’re back to where you were, in like 5 seconds.

      Obviously I could go on and on, what I’m trying to say is that it’s a seriously bad ass, awesome tool – and you don’t have to be a bad ass to use it. You can just sort of grow into it, picking up new stuff as you go along.

      I was also really put off by it when I first tried it. I opened it up, took one look at it and said jesus, man, look at all those buttons and controls, and I was done.

      Thing is, it’s an insanely configurable IDE and there’s not much you can’t change. It was the Laracast videos linked above that finally got me on board.

      Jeffrey shows how to get it set up and completely stripped down – here’s what my setup looks like in its default state (attached below) – super minimal, and all those cool controls are just a couple keyboard shortcuts away.

      I highly highly suggest taking the time to watch a couple of those videos. I’m pretty sure he even steps through how to setup Sublime keyboard shortcuts so you can get up and running really quickly.

      Wow, I had no intention of writing that much, sorry! :-p

      Here’s that link again, just for convenience sake – https://laracasts.com/series/how-to-be-awesome-in-phpstorm 🙂

      • I am not saying that PhpStorm is bad. I am just OK with Sublime Text. There is nothing you mentioned here, or mentioned in the post above that can’t be done with Sublime Text.

        About the LaraCasts, the fact is, I have already watched ’em so I know how PhpStorm works, but I still didn’t see the need of making a shift.

        I use iTerm, ZSH shell and oh-my-zsh, there is no way I would give it away for an IDE based terminal, it just doesn’t come near the setup and speed I have in my workflow with Sublime Text and iTerms and Gulp etc.

        So, I’d retain the point, I made, I think @jb510:disqus is right, I am not shifting to it mostly coz I don’t really need it and the learning curve is still not worth the effort.

        • smutek

          Fair enough, and I totally get it. I wasn’t trying to say that PHPStorm is “better”, sorry if it came off that way!

          Initially I was responding to your comment:

          “and there is so much more Sublime Text can do, when it comes to CSS/Front-end stuff.”

          …because it isn’t accurate, but I ended up raving about PHP Storm as well. 🙂

          In your last comment you say PHPStorm doesn’t come near the speed of your current workflow – yet you don’t actually use PHPStorm so, technically you’re not able to accurately make that comparison.

          Same for “the learning curve is not really worth the effort” – you wouldn’t really know is the learning curve is worth the effort because you haven’t learned it. 😉

          Regardless, I get it. Different strokes and all that, at the end of the day the best tool is the tool that works best for you. 🙂

          FWIW – I’m also an iTerm / ZSH user 🙂 and I own and use Sublime as well.

          Have a good one!

          • That’s fair. I guess we are both trying to talk about same facts here. Just as I don’t know a lot about PhpStorm, so could be the case with you and Sublime Text.

            About

            “and there is so much more Sublime Text can do, when it comes to CSS/Front-end stuff.”

            “the learning curve is not really worth the effort”

            I never meant any general perception when I wrote this, I meant “for me” it ain’t worth the effort, not right now anyway.

            But hey, I have it installed, and I am trying to push myself to start using it for Plugin development, though I am more of front-end guy.

            🙂 Hope so that this clears up the air.

      • Thanks for your comment, worth the read – didn’t know you could jump to Sass variable definitions as well!

  • Configuring XDebug is not so intuitive when developing using a virtualized environment, for example Varying Vagrant Vagrants. This video shows how to map VVV XDebug with PhpStorm: https://www.youtube.com/watch?v=EsL6mAFEsvY – additionally to XDebug I also use this utility that works in the browser to run live WordPress and general PHP code: https://github.com/nekojira/wp-php-console

  • Make the switch, Brad!

    Usually the objections to switching from SublimeText to PHPStorm are all the objections stated above… it’s slow, already have SublimeText customized the way you need, I don’t have time, etc. I had all of those objections, tried to switch once but said “I don’t have time” and didn’t try it again for a while. I’m primarily a back-end dev.

    Later, I found myself in a project that I had an extremely tough time navigating and wrapping my head around due to the amount of stuff flying around. I was maxing out SublimeText’s features every way I could with plugins and such. So, I forced myself to use PHPStorm because I knew I’d get better visibility. I set the key mappings how I want, Google’d how to do things I normally did in SublimeText but wanted to do in PHPStorm… and surprisingly, the switch was a lot faster and smoother than I thought it would be. You can customize literally everything and learn as you go… you don’t need all the answers right now.

    I’m a much faster, less frustrated, more knowledgeable, and more confident developer now. I couldn’t live without many things mentioned in this article… most notably the implementation of Xdebug.

    I found this by Jeffrey Way in trying to make my switch, who’s pretty invested in the Laravel community, but he explains how he switched from SublimeText to PHPStorm, and areas where he still uses SublimeText sometimes — https://laracasts.com/series/how-to-be-awesome-in-phpstorm

    • This is exactly the same approach I took when I first started with PhpStorm. I didn’t try to learn the entire IDE, I pretty much disabled everything bar Xdebug so it was essentially a Sublime clone. Overtime I started enabling additional features and learned them as I went, which made the switch much less intimidating.

      Xdebug is such a game changer, it’s hard to believe I lived without it for so long.

  • PHPStorm is bloated, ugly and slow. And I LOVE it to bits! couldn’t code without it. My previous editor was also Sublime Text.

    Yes, there is a learning curve, and it’s easy to slip back to what you know. But, in a sense, you’re just cutting off your nose to spite your face.

    You’re doing yourself a disservice by not persisting.

    PHPStorm will save you time once you know it. It’s features will save you more time than those of ST (Even with it’s excellent add on packages).

    You might think you’re saving time by going back and using ST or whatever you are familiar and therefore quick with, but ultimately, you’re not. You’re costing yourself time.

  • Chris Greenbag

    brad wont fit in the gloryhole and thats why we all love brad

  • searchwp

    This covers so many reasons PhpStorm is my editor of choice for WordPress development. There are also a couple of other nuggets that are super handy too!

    A little thing that’s kind of one of my favorite tools: a full-on console as a pane in the editor. Not having to alt+tab to my terminal 400 times a day is nice.

    Do you need to inspect HTTP responses? It’s built right in! Tools > Test RESTful Web Service

    I (absolutely) love Sequel Pro, but PhpStorm can get the job done too.

    It took me a while to appreciate it all, but the niceties of an IDE truly do have a visible impact on your productivity in my opinion. Little things like automatically parsing a project-level list of TODO’s that we scatter all over the place in a pane is awesome.

    The VCS tools are really powerful too. As others have mentioned they’re not the prettiest things to look at, but the diffing and merging is super powerful.

    PhpStorm also recently built in support for Vagrant and Grunt which is neat. Yes you can absolutely do all of that in the terminal (which I do using PhpStorm’s terminal pane) but having a UI is just sometimes… nice.

    We talk editors a lot, and I must admit there are days where I covet the speed/agility of Sublime/Atom but I always end up realizing that instead of using PhpStorm all day I end up switching to/from a combination of 3-5 other apps throughout the day to get the same work done.

    PhpStorm’s recent change to a Creative Cloud-like licensing model is ruffling a lot of feathers, but I don’t see it as a greedy money grab, I’ve been happily renewing my license for the past 3 years and I’m glad to see Jetbrains is taking steps to ensure the company will continue to be able to work on my favorite editor.

    • Thanks for highlighting some extra great features Jonathan!

  • Evan

    PhpStorm and Sublime Text are both fantastic to use, but one will never be as good as the other at what they do best.

    Really cool to see the series at Laracasts dropped here, Jeffrey really does a great job with that (I’m also a huge fan of that site in general).

    Like many, I was an avid ST user for many years before really experiencing a full IDE. The WordPress integration is also really nice. Being able to jump to the invocation of an action or filter is incredibly useful.

    With that said, I prefer to use PhpStorm for projects, but I still use ST a lot, again for its speed when I don’t need all the bells and whistles. I also really love features like the “hot exit” that is possible with ST.

    It’s not one or the other though. You don’t need to break up with ST to use PhpStorm. If you know two tools, you’ll naturally choose the most appropriate one for the task at hand. If you only know one, you don’t have a choice.

    • It’s not one or the other though. You don’t need to break up with ST to use PhpStorm

      So true Evan, thanks for your insight.

  • donkeyjong

    I gotta say with PhpStorm 9 and reading this blogpost my fingers are itching to try it out!

  • Mike

    Our team started using PHPStorm several months back and have loved it. The learning curve is a bit steep, but there are so many resources online for discovering what’s great about PHPStorm that it hasn’t been too daunting. This Reddit post was one I ran across recently and despite that it’s getting a little old now, I still found some great nuggets. One of my favorites was the CTRL-Shift-A command, which lets you enter text describing a command and PHPS makes suggestions on matching commands with keyboard shortcuts. 🙂

    https://www.reddit.com/r/PHP/comments/1dzggz/i_just_got_phpstorm_i_love_it_what_are_some_great/

  • Hi , I’ve been reading some of your posts regarding phpstorm wordpress development. Many are from 2013 & 2015, but a lot of the content seems equally applicable today. Thanks for sharing.

  • You may want to tell “Brad” to check out the 2017.1 EAP of PHPStorm. It is lightning fast. I did several very unscientific tests against Sublime Text 3 and couldn’t see much of a difference in speed. 😉

  • I’m curious how projects are set up for WordPress. For example if I only want to develop a theme, then I’m really only editing the plugins and themes folders. But if I sync just those folders to my localhost, then I can’t run the site or debug or anything because I only have those two folders. But downloading the entire WP site seems like overkill.
    And if I’m using a staging site to begin with, why add another layer by creating yet another dev version on my localhost which then has to be deployed to staging, which has to be deployed again to live?

    So what is the best way to set up a project in PHPStorm if there is a live site, a staging site, and my localhost? Do I set it up as FTP and sync the entire WP install? Then how do I “run” the site, because it will want to run it from the local files, and the DB isn’t set up to work this way, only the files are downloaded.

    Is it better to just bite the bullet and download the entire site to my localhost? If so, I have to sync the DB as well I guess and use the exact same DB name/pass, etc because it will be sharing the same wp-config values. Or is there a good way to not have to use my localhost, and just work directly off our staging servers? Note that I still would like features like live browser refreshing and using the debugger.

    Ideas?

  • Great blog post and agree Phpstorm rocks for WordPress. Further detailed workflow tutorials on it are always welcome.