1

I am trying to execute a command from within my theme's functions.php using the method described here: https://make.wordpress.org/cli/handbook/internal-api/wp-cli-runcommand/

And I am getting the following error:

"Class 'WP_CLI' not found"

I've wrapped my function in the following code, which gets rid of the error:

if ( class_exists( 'WP_CLI' ) ) { }

However... I still need to figure out how can I make it so my theme's functions.php file correctly loads the WP_CLI class?

I have WP_CLI installed and am using it fine via command-line, but I am trying to add some extra functionality that would have it execute from a function within my theme.

Thank you for any help that you can provide.

Michelle
  • 113
  • 4
  • 13
  • This may be an [XY Problem](https://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). *Why* are you trying to execute WP_CLI from within your theme - that's not normally how you would use WP_CLI.... normally, it's useful for administrating a site, or for testing / debugging - but I would not expect my _theme_ to run WP_CLI. – random_user_name Nov 21 '17 at 02:30

1 Answers1

0

Where is your WP_CLI class installed? You need to locate the class's location and add an autoload, or use require in your functions.php file like require('path/to/WP_CLI.php')

More info: http://php.net/manual/en/function.require.php

  • without knowing the root of WP_CLI, it may be hard to locate the class. Try contacting your system admin or whoever has access to the installation and get the path to WP_CLI root. Then you can put the correct path into your code ` define( 'WP_CLI_ROOT', '/path/to/wp-cli' ); include WP_CLI_ROOT . '/php/wp-cli.php'; ` – Long M K Nguyễn Nov 21 '17 at 00:23