Reputation: 57
Can I run WP-CLI https://wp-cli.org/
command through PHP script, so I can install user selected WordPress themes automatically with PHP script
Upvotes: 1
Views: 1168
Reputation: 76
You can do something like this:
exec('wp site list --field=url --archived=0', $output);
foreach($output as $url) {
echo $url . "\n";
echo exec("wp --url=$url plugin activate this-plugin");
}
Run it in a PHP script in your home directory.
Upvotes: 1
Reputation: 96
As long as you can use the exec() or similar command. I use something like this to output the result of a wp-cli command:
<pre>
<?php
exec("wp --info", $result);
echo implode(PHP_EOL, $result); // join multi-line return result
?>
</pre>
Or simply:
<?php exec("wp --info");
See this answer: https://wordpress.stackexchange.com/questions/219230/utilize-wp-cli-from-inside-wordpress-not-ssh for further discussion.
Upvotes: 1