Using wp-cli through PHP

岁酱吖の 提交于 2019-12-11 04:55:32

问题


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


回答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.




回答2:


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.



来源:https://stackoverflow.com/questions/37294485/using-wp-cli-through-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!