Using PhpStorm for WordPress Development

  • Tutorial
A few weeks ago , support for the popular WordPress CMS was added to PhpStorm 8 (available through the Early Access Program) . The latest PhpStorm 8 EAP build can be downloaded for free right now, so everything described in this training material can already be tried, and we, in turn, will be grateful for the feedback in our bugtracker .

Comprehensive information on supporting WordPress in PhpStorm can be found in the English-language material WordPress Development using PhpStorm . In this post we will talk about the most important features included in WordPress support in PhpStorm.

Currently, support includes:
  • PhpStorm integration with WordPress for existing projects and new plugins;
  • setting up a working environment for development for WordPress;
  • setting standards for WordPress code design and following them;
  • support for hooks (including auto-completion for parameters of registering functions; navigation from functions that register hooks to calls of hooks; and other functions);
  • search for documentation on WordPress.org directly from the editor;
  • integration with WordPress WP-CLI command line tools.


WordPress integration for existing projects and new plugins


Enabling integration in existing projects

If the project you are working on is recognized as a WordPress plugin, you will automatically be asked to enable WordPress support in the project.

You must enter / select the path to the WordPress installation folder ( WordPress Installation Path - the root installation folder of WordPress, in which the wp-admin and wp-includes folders are located ).



Integration with WordPress for a project can be turned on or off in Settings | WordPress | Enable WordPress Integration .



Creating a New WordPress Plugin

A new WordPress plugin can be created from the Welcome screen or via File | New project . Select the type of project WordPress Plugin and, after clicking OK, enter / select the path to the installation of WordPress ( WordPress Installation Path ).



The initial plug-in file in the project will be created automatically according to the standard template ( plugin-name.php file with the corresponding meta-information about the plugin).



Setting up a development environment for WordPress


Regardless of the method of activating integration with WordPress (by creating a new plugin or enabling support for an existing project), the IDE will check the configuration for compliance with the best development practices for WordPress. If the current configuration can be improved, pop-up windows will appear with suggestions for auto-configuration of the development environment.



All PhpStorm offers within the framework of integration with WordPress can also be viewed in the Event Log window .



PhpStorm with WordPress enabled provides the following development environment auto-configuration options:
  • Include Path configuration (in the case where the wp-content directory and / or your plugin are located OUT of the WordPress installation);
  • Content Root configuration (in the case where the wp-content directory and your plugin are located inside the WordPress installation);
  • switching to the WordPress code design standard (the code design standard can be changed in Settings | Code Style | PHP . The WordPress code design standard can be applied by choosing Set from ... | Predefined Style | WordPress ).


WordPress hooks support (WordPress Hooks)


Auto-completion for WordPress function parameters such as Action and Filter (auto-completion of hooks)

All hooks declared in the WordPress core and plug-ins are indexed by the PhpStorm editor when integration with WordPress is enabled, which makes it possible to display hook names in code completion (by the standard Ctrl + Space action ) for parameters of the standard action and filter functions (for example, add_action and add_filter ).



Navigation from registering hooks (functions like action and filter) to calling hooks

Navigation can be done from WordPress hook registration locations (using registration functions such as add_action and add_filter ) to hook invocations by clicking on the navigation icon in the left margin of the editor:



Callback with hook registration

The transition from declaring a function / method specified by the second parameter to the actions / filter hook registration functions ( add_action and add_filter ) is performed by the action of Ctrl + Click ( CMD-Click on Mac OS X) or Ctrl + B ( CMD-B on Mac OS X) .



Navigate to Symbol ... for hooks

Using Navigate | Symbol ... ( Ctrl + Alt + Shift + N on Windows / Linux, CMD-ALT-O on Mac OS X) you can search for hook calls and easily jump to them. For the same purpose, you can use the Search Everywhere ( Double-Shift ) action .



Other functions supporting hooks are also implemented, for example, Find Usages .



Search WordPress.org documentation directly from the editor


Going to the WordPress documentation on the official resource http://WordPress.org is possible directly from PhpStorm using text search. Just select the code element (text, function, etc.) that you want to find in the documentation, and select the Search on WordPress.org action from the editor’s context menu.



The default browser will open with search results for WordPress documentation.



Integration with WordPress WP-CLI command line tools



WP-CLI is a command-line toolkit for managing WordPress installations. You can update plugins, implement multisite installations, and much more (all without a browser).

We recommend installing WordPress WP-CLI command-line tools by following the instructions on the official website (by downloading the PHAR package) or by using Composer directly from PhpStorm ( wp-cli / wp-cli package ).



For more information on WP-CLI configuration and many other features included with PhpStorm's WordPress support, see the full tutorial on developing WordPress using PhpStorm .

You can findwith the tasks and bugs we already knew about integrating with WordPress. We welcome any comments on the ongoing support of WordPress in PhpStorm and other subsystems of our IDE.

Download the latest PhpStorm 8 EAP build with WordPress support and many more innovations right now!

Program with pleasure!
~ JetBrains PhpStorm Team

Also popular now: