Michelle
Michelle

Reputation: 133

Using WPI_CLI in WordPress theme's functions.php

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.

Upvotes: 1

Views: 1154

Answers (1)

Long M K Nguyễn
Long M K Nguyễn

Reputation: 817

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

Upvotes: 0

Related Questions