Updated::
I am having issues when adding a custom cli command into an existing wordpress theme. When I run wp --info
I get the following:
PHP binary: /usr/local/Cellar/php70/7.0.13_6/bin/php
PHP version: 7.0.13
php.ini used: /usr/local/etc/php/7.0/php.ini
WP-CLI root dir: phar://wp-cli.phar
WP-CLI packages dir:
WP-CLI global config:
WP-CLI project config: /Users/julie/isl-site/isl-site/wp-cli.yml
WP-CLI version: 1.0.0
However, when I register the example command within my theme/functions.php
function foo_command( $args ) {
WP_CLI::success( $args[0] );
}
WP_CLI::add_command( 'foo', 'foo_command' );
I get the following errors:
Uncaught Error: Class 'WP_CLI' not found in /my-site/public/wp-content/themes/my-theme/lib/theme-functions.php:278
Stack trace:
15:23:29 web.1 | #0 /Users/julie/my-site/public/wp-content/themes/my-theme/functions.php(36): require_once()
15:23:29 web.1 | #1 /Users/julie/my-site/public/wp/wp-settings.php(387): include('/Users/julie/...')
15:23:29 web.1 | #2 /Users/julie/my-site/public/wp-config.php(212): require_once('/Users/julie/...')
15:23:29 web.1 | #3 /Users/julie/my-site/public/wp/wp-load.php(44): require_once('/Users/julie/...')
15:23:29 web.1 | #4 /Users/julie/my-site/public/wp/wp-blog-header.php(13): require_once('/Users/julie/...')
15:23:29 web.1 | #5 /Users/julie/my-site/public/index.php(5): require('/Users/julie/...')
15:23:29 web.1 | #6 {main}
15:23:29 web.1 | thrown in /Users/julie/my-site/public/wp-content/themes/my-theme/lib/theme-functions.php on line 278
Any insight on how to resolve this issue?
wp-cli.yml
file