
A few weeks ago
support for the popular CMS WordPress
was added to PhpStorm 8 (available as part of the Early Access Program). The latest build of PhpStorm 8 EAP can be
downloaded for free right now, so everything described in this tutorial can already be tried, and we in turn will be grateful for the feedback in our
bugtracker .
Comprehensive information about WordPress support in PhpStorm can be found in the English-language
WordPress Development using phpStorm . In this post we will talk about the most important features included in supporting WordPress in PhpStorm.
Currently support includes:
- PhpStorm integration with WordPress for existing projects and new plug-ins;
- setting up a working environment for developing under WordPress;
- setting standards for the design of WordPress code and follow them;
- hook support (including autocompletion for parameters of registering functions; navigation from hook registering functions to hook calls; and other functions);
- search for WordPress.org documentation 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 be automatically prompted to include WordPress support in the project.
')
You must enter / select the path to the WordPress installation folder (
WordPress Installation Path is the root folder of the WordPress installation, which contains the
wp-admin and
wp-includes folders).

The integration with WordPress for the project can be enabled or disabled in
Settings | Settings | WordPress | Enable WordPress Integration .

Creating a new WordPress plugin
A new WordPress plugin can be created from the start screen (
Welcome ) 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 using a standard template (the
plugin-name.php file with the corresponding meta-information about the plugin).

Setting up the working environment for developing under WordPress
Regardless of the method of activating integration with WordPress (by creating a new plug-in or including support for an existing project), the IDE will check the configuration for compliance with best development practices for WordPress. If the current configuration can be improved, a pop-up window will appear with suggestions for autoconfiguring the development environment.

All PhpStorm offers as part of WordPress integration can also be viewed in the
Event Log window.

WordPress-enabled phpStorm offers the following options for autoconfiguring the development environment:
- Include Path configuration (in the case when the wp-content directory and / or your plugin is OUTSIDE of the WordPress installation);
- Content Root configuration (in the case when the wp-content directory and your plugin are INSIDE the installation of WordPress);
- switch to the WordPress code design standard (the code design standard can be changed in the Settings | Code Style | PHP settings. The WordPress code design standard can be applied by selecting Set from ... | Predefined Style | WordPress ).
WordPress hook support (WordPress Hooks)
Autocompletion for WordPress Action and Filter Function Parameters (Hook Autocompletion)
All hooks declared in the WordPress core and connected modules are indexed by PhpStorm when WordPress integration is enabled, which makes it possible to display hook names in code completion (by the standard action
Ctrl + Space ) for the parameters of the standard action and filter functions (for example,
add_action and
add_filter ).

Navigation from registering hooks (functions of type action and filter) to calls of hooks
Navigation can be done from WordPress hooks' registration sites (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 the declaration of the function / method specified by the second parameter of the actions registration functions actions / filter (
add_action and
add_filter ) is made by the action
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 navigate to them. For the same purpose, you can use the
Search Everywhere (
Double-Shift ) action.

Implemented and other functions that support hooks, such as
Find Usages (search for uses).

Search WordPress.org documentation directly from the editor.
The transition to WordPress documentation on the official resource
http://WordPress.org is possible directly from PhpStorm using text search. Simply 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 the search results for the WordPress documentation.

WordPress WP-CLI command line integration
WP-CLI is a command-line toolkit for managing WordPress installations. You can update plugins, implement multisite installations and more (all without using 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 using Composer directly from PhpStorm (
wp-cli / wp-cli package ).

More information about the WP-CLI configuration and many other features included in WordPress support in PhpStorm can be found in the
complete WordPress development training material using PhpStorm .
You can
familiarize yourself with the tasks and bugs already known to us for integrating with WordPress. We welcome any comments on current WordPress support in PhpStorm and other subsystems of our IDE.
Download the latest PhpStorm 8 EAP build with WordPress support and many other new features right now!
Program with pleasure!
~ JetBrains PhpStorm Team