1

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

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.