Detect if WP is running under WP-CLI

Within the php/wp-cli.php we find these lines:

// Can be used by plugins/themes to check if WP-CLI is running or not
define( 'WP_CLI', true );
define( 'WP_CLI_VERSION', trim( file_get_contents( WP_CLI_ROOT . '/VERSION' ) ) );
define( 'WP_CLI_START_MICROTIME', microtime( true ) );

so you could check if WP_CLI or WP_CLI_VERSION are defined.

Leave a Comment