Get the most out of your IDE for WordPress!
Speed up development with handy features and shortcuts
We’ve called out deals for our preferred code editor or IDE (integrated development environment) PHPStorm before, since we believe it to be one of the best tools on the market for WordPress developers. Some of the benefits are obvious: an easy navigation, color-coordinated formatting, and built-in support for WordPress-related functions are all handy features to improve your development experience. But the waters go much deeper than that with PHPStorm. There are truly fathomless depths to the settings and shortcuts that PHPStorm offers. We’re going to outline some of our favorites here that speed up development, but this is barely scratching the surface of what you can do with a powerful IDE like PHPStorm.
This article covers PHPStorm in particular, but it’s always possible your code editor of choice has similar features. Don’t be afraid to hit up Google and see if you can improve your development cycle without learning a whole new system!
Automatic formatting
PHPStorm comes loaded up with automatic color coding for different elements and attributes of just about every coding language you can think of. And when you start typing, the program does its best to automatically format what you’re typing to be clean and easily readable. But it’s not a perfect system, and mistakes or changes happen that result in that formatting being messed up. Not to worry: PHPStorm has one simple shortcut to automatically format the entire file you’re in! A quick press of CMD+Option+L (or picking “Reformat Code” under the Code menu) tidies up the entire file, restoring it to an easily-readable state.
If PHPStorm’s formatting doesn’t match your own, there are extensive settings to tell the system what exactly you’re looking for. Another quick shortcut: hit CMD+, to open up the settings, then search for “Code Style” to find the settings to configure how you want your code to be formatted. You can even specify different formatting schemes for different languages, or set it up to automatically run the formatting feature every time you save.
Automatic completion and contextual prompts
If you use PHPStorm, you’ve probably seen this one in action already. Start typing, and then stop before finishing the word. PHPStorm will provide a list right there of what you might be looking for, and you can navigate with the arrow keys and tab to confirm your selection without having to remove your hands from the keyboard. The system looks for functions you’ve already typed, global variables in the language you’re coding in, and WordPress functions and variables if applicable.
Past that, after you’ve chosen the function, PHPStorm will tell you the variables said function is expecting. For your own custom functions, you can provide extra information about these parameters beyond the name of the variable in a comment block above the function, too. This is super handy in cases where you don’t use a function often: PHPStorm reminds you of the variables you’ll need to pass without having to crawl over your code looking for the function or heading to Google.
Find declaration (or usages)
But if you do need to look at that function (or any variable, for that matter), PHPStorm has you covered too. A quick CMD+B on any function or variable will take you to the location in the code where it was defined. And the reverse is true too: if you use the same shortcut on the initial declaration, you’ll be provided with a list of all places that function or variable is used throughout the project. This is the first of our search tips and tricks, since we’ve saved so much time and momentum by being able to find what we’re looking for in mere seconds instead of scanning code searching for the exact line we’re trying to find.
Cross-file search (and search EVERYTHING)
Let’s say you know you created a function, but it’s not used anywhere yet, and you can’t remember where you defined it. Once, PHPStorm comes to the rescue! A simple search is pretty common functionality, and CMD+F lets you search the file you’re in. But adding the SHIFT key into the mix opens up a window to let you cross-file search. By default, this searches for the content you type in every single file in the project. You can narrow that down to specific types of files, or a subset or individual folder, but this is such a powerful feature to automatically crawl your entire project for the exact thing you’re looking for.
Not looking for a line of text, like a function or variable? Hit SHIFT twice to search absolutely everything in the project: files, classes, actions, and even specific symbols if you need to. And unlike the cross-file search, you don’t even need to know the exact name of what you’re searching for. In the search everything window, PHPStorm makes guesses and assumptions to show you anything you might be looking for, not just the exact text.
Renaming and other refactorings
Imagine you discovered (after using the automatic completion feature from before), that you had a typo in a crucial variable name. There are a few options: you could just leave it, and accept the typo. Or you could manually find every usage (with CMD+B, maybe) and manually change every instance. Or, with PHPStorm, you can simply right-click, Refactor, Rename, and marvel as PHPStorm automatically updates every instance of the variable to your correction.
Renaming is our most common choice when refactoring, but there are many other options in that menu. You can have PHPStorm programmatically introduce a new variable or parameter, safely delete a function or variable by checking for usage automatically, or have the system move the declaration and other dependencies to another location.
Quick list
There are even more features we use constantly that aren’t big enough to warrant their own section. But even these little tips and tricks add up to big savings over time!
- We touched on this with the contextual prompts for function parameters, but you can define a plethora of extra information for functions, variables, constants, and more by just placing a comment block ( started with /** ) above it. Add some information about the function itself, explain how the parameters are used, and more.
- A handy little feature for advanced commands: PHPStorm allows you to open a terminal window right inside the platform
- Made a change, let some time pass, and realize you need to undo it? It’s too late for CMD+Z, but head to File > Local History to find both manual and automatic saves PHPStorm has in its memory.
- Open up two different files next to each other, and even view differences between them if you happen to be looking at two different versions of the same file.
- Have a lot of files open? Right-click on any highlighted tab and choose “Close All Tabs” or “Close All Other Tabs” to clean up your view in an instant.
Once again, this is barely scratching the surface of the settings and hidden power of an advanced IDE like PHPStorm. Take some time to explore for your own, and happy coding!