diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index d3ae4fb1f1..64e58679ea 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -396,6 +396,11 @@ private static function wp_hook_build_unique_id( $tag, $function, $priority ) { * @return true True on success, false if deferred, hard error if registration failed. */ public static function add_command( $name, $callable, $args = array() ) { + // Bail immediately if the WP-CLI executable has not been run. + if ( ! defined( 'WP_CLI' ) ) { + return false; + } + $valid = false; if ( is_callable( $callable ) ) { $valid = true;