PhpStorm 2023.3 Help

Use the WP-CLI command line tool from PhpStorm

To run WordPress in the command line mode, you need to either declare the wp-cli/wp-cli package as a Composer dependency or download the wp-cli.phar archive from https://wp-cli.org/.

Install the WP-CLI package using Composer

  1. Inside composer.json, add the wp-cli/wp-cli dependency record to the require or require-dev key. To get code completion for the package name and version, press Ctrl+Space.

  2. Do one of the following:

    • Click the Install shortcut link on top of the editor panel.

    • If the Non-installed Composer packages inspection is enabled, PhpStorm will highlight the declared dependencies that are not currently installed. Press Alt+Enter and select whether you want to install a specific dependency or all dependencies at once.

Configure WP-CLI as a command line tool

  1. In the Settings dialog (Ctrl+Alt+S) , go to Tools | PHP Command Line Tool Support.

  2. Click the Add button on the toolbar.

  3. In the Command Line Tools dialog, choose WP-CLI from the list, and specify its visibility level (Project or Global).

    the Command Line Tools dialog
  4. When you click OK, the WP-CLI dialog opens.

    Choose the way to run WP-CLI:

    • Installed via PHAR: Choose this option to launch WordPress through a PHP script or have PhpStorm detect and start the launcher in the wp-cli.phar archive.

      Choose one of the configured PHP interpreters from the PHP Interpreter list. For more information, refer to Configure local PHP interpreters and Configure remote PHP interpreters.

      In the Path to phar field, specify the location of the wp-cli.phar archive. Type the path manually or click the Browse button and choose the desired location in the dialog that opens.

    • Executable available (installed via Composer, and so on): choose this option to launch WordPress through an executable file, which is available when you install WordPress using a package management tool, for example, Composer.

      In the Path to wp.bat field, specify the location of the wp.bat or wp executable file. If you used Composer, the default location is \vendor\wp\cli\bin\wp or \vendor\wp\cli\bin\wp.bat. Type the path manually or click the Browse button and choose the desired location in the dialog that opens.

  5. Click OK to apply changes and return to the PHP Command Line Tool Support page. Optionally, click the Edit button to edit the tool properties, or the Edit Source button to customize the commands set. For more information, refer to Customize a tool.

Run WP-CLI commands

You can run WP-CLI commands and analyze their output right in PhpStorm, just as the commands of any other command line tools, refer to PHP command line tools.

  • Go to Tools | Run Command or press Ctrl twice.

    In the Run Anything window that opens, type the call of the command in the <wp> <command> format.

    The command execution result is displayed in the Run tool window.

    Running a wp-cli command

Terminate a command

Debug WP-CLI commands

Wordpress commands are defined in controller classes that extend WP_CLI_Command, as well as in arbitrary functions. To debug a command, it is crucial that you initiate a debugging session for the command itself, and not the controller class or the file it is defined in. Otherwise, the Wordpress bootstrapping process will be skipped, and the execution will fail.

  1. In the controller class or the file corresponding to the selected command, click the editor gutter at a code line where you want to set a breakpoint.

    Set a breakpoint in a Wordpress command
  2. Create a run/debug configuration that will run the wp-cli tool with the selected command. In the main menu, go to Run | Edit Configurations, then click the Add button and choose PHP Script from the list.

    Run/Debug configuration: PHP script
  3. In the PHP Script dialog, provide the run/debug configuration parameters.

    • In the File field, provide the path to the wp-cli executable file.

    • In the Arguments field, type the actual command and its arguments, such as my-command print_year.

    Run/Debug Configurations dialog for Wordpress CLI command
  4. On the PhpStorm toolbar, select the created run/debug configuration and click the Debug button. The command execution will stop at the specified breakpoint.

    Debug a Wordpress command
Last modified: 25 March 2024