WordPress stubs and plugin for Psalm static analysis.

Installs: 265 626

Dependents: 17

Suggesters: 0

Security: 0

Stars: 67

Watchers: 24

Forks: 17

Open Issues: 2


3.1.1 2024-02-29 11:38 UTC

This package is auto-updated.

Last update: 2024-05-31 10:55:51 UTC


Packagist Packagist

Write type-safe WordPress code.

This Psalm plugin provides all WordPress and WP CLI stubs, so your WordPress based project or plugin will have type information for calls to WordPress APIs. This ensures your WordPress plugin or theme has less bugs!

  • Stubs for all of WordPress Core
  • Stubs for WP CLI
  • Types for apply_filters return values.
  • Types for add_filter / add_action
  • Configuration options to use your own stubs


Please refer to the full Psalm documentation for a more detailed guide on introducing Psalm into your project.

After Psalm is installed, install this package and enable the plugin:

composer require --dev humanmade/psalm-plugin-wordpress
./vendor/bin/psalm-plugin enable humanmade/psalm-plugin-wordpress


If you follow the installation instructions, the psalm-plugin command will add this plugin configuration to the psalm.xml configuration file.

<?xml version="1.0"?>
<psalm xmlns="">
	<!-- project configuration -->

		<pluginClass class="PsalmWordPress\Plugin" />

Further details about plugins can be found on Psalm's website.

Default WordPress stubs

If you do not want to use the default WordPress class/method/function stubs, which are part of this plugin, useDefaultStubs must be set to false:

<pluginClass class="PsalmWordPress\Plugin">
	<useDefaultStubs value="false" />

Default WordPress hooks

If you do not want to use the default WordPress hooks, which are part of this plugin, useDefaultHooks must be set to false:

<pluginClass class="PsalmWordPress\Plugin">
	<useDefaultHooks value="false" />

Custom hooks

You can also provide custom hooks:

<pluginClass class="PsalmWordPress\Plugin">
		<directory name="some/dir/hooks" recursive="true" />
		<directory name="/absolute/other/dir/hooks" />
		<file name="my-special-hooks/actions.json" />

If a directory is provided, the plugin will search for the following files:

  • actions.json
  • filters.json
  • hooks.json

The plugin expects a JSON representation of the hooks as per wp-hooks/generator.

Require passing all parameters

If you want to get an error if apply_filters and do_action do not have the same number of parameters in all cases, requireAllParams must be set to true:

<pluginClass class="PsalmWordPress\Plugin">
	<requireAllParams value="true" />

WordPress paths

To help Psalm analyze your project you might need to define some of WordPress' default global constants such as those for paths.

<?xml version="1.0"?>
<psalm autoloader="tests/bootstrap.php" xmlns="">
	<!-- project configuration -->

The following example bootstrap file is for a Bedrock installation:


require_once dirname( __DIR__ ) . '/config/application.php';

define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' );

define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );

You could require WordPress' default constants functions but that requires a lot more boilerplating to allow those functions to effectively define constants.

Interested in contributing?

Feel free to open a PR to fix bugs or add features!

In addition, have a look at Psalm's contribution guidelines.

Who made this

Created by @joehoyle, maintained by the Psalm community.