WP-CLI

A command line interface for WordPress

Docs » Internal API » Registration

WP_CLI::add_hook()

Schedule a callback to be executed at a certain point.


Usage

WP_CLI::add_hook( $when, $callback )
$when (string) Identifier for the hook.
$callback (mixed) Callback to execute when hook is called.
@return (null)

Notes

Hooks conceptually are very similar to WordPress actions. WP-CLI hooks are typically called before WordPress is loaded.

WP-CLI hooks include:

WP-CLI commands can create their own hooks with WP_CLI::do_hook().

# `wp network meta` confirms command is executing in multisite context.
WP_CLI::add_command( 'network meta', 'Network_Meta_Command', array(
   'before_invoke' => function () {
       if ( !is_multisite() ) {
           WP_CLI::error( 'This is not a multisite install.' );
       }
   }
) );

Internal API documentation is generated from the WP-CLI codebase on every release. To suggest improvements, please submit a pull request.