Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
- I have Zend framework 2 application (PHP), via which I want to use WP-CLI functionality. near Zend project I have WordPress project, which I want to maintain from Zend via WP-CLI.
- I see in the docs that WP-CLI also written on PHP. I dreamed that I install WP-CLI via composer in root of my project and can use its classes there.
- After installing via composer in WP-CLI's sources I see functions from WordPress (like as is_multisite and etc) and I little disappointed :).
Can I in some way use WP-CLI sources directly from my Zend-project without calling commands via terminal?
for example (in abstract programming language):
$command = new WP_CLI::command('command_name subcommand_name', $params, $assoc_params, .....);
$result = $command->execute();
Or WP-CLI was made only as part of the WordPress project as way for extending it's commands and it is unable to use them as I am trying?
asked Feb 16, 2017 at 17:10
This is probably unwise. WP-CLI is developed as a command line utility and might not maintain internal structure between releases.
Since everything has to run as root in any case, there is no real difference between executing a WP-CLI command via a shell (A.K.A
exec and its family of functions), or by calling whatever API.
answered Jan 22, 2018 at 11:16
Mark KaplunMark Kaplun
23.1k77 gold badges3939 silver badges6363 bronze badges
WP_CLI class has a
runcommand method that launches a new child process to run a specified WP-CLI command. According to the docs, you can use it like this:
$options = array(
'return' => true, // Return 'STDOUT'; use 'all' for full object.
'parse' => 'json', // Parse captured STDOUT to JSON array.
'launch' => false, // Reuse the current process.
'exit_error' => true, // Halt script execution on error.
$plugins = WP_CLI::runcommand( 'plugin list --format=json', $options );
answered Jan 22, 2018 at 11:05
3,75411 gold badge2020 silver badges2525 bronze badges