0 votes
in Website Design by (1.9k points)

I'm new to phar files

How can I use wp-cli in a php page without going through command line?

Instead of using php to execute command line to execute wp-cli:

<?php
exec('php wp-cli.phar cli version', $out, $ret);

I want to use classes directly. something like this:

<?php 
include 'wp-cli.phar';
echo new CLI_Command().version();

1 Answer

0 votes
by (2.4k points)

You don't

Sometimes a phar file can be used from the web in a browser, but this assumes a website is inside the phar archive. WP CLI isn't web based, it's a pure CLI application.

If you don't have CLI access on a host, consider cloning your site on to your local machine, running the necessary cli commands locally, then uploading the result to your remote server.

If you're trying to make use of WP CLI internal classes, you should look at the GitHub repository, however, keep in mind loading WP CLI naively will result in issues, since WP CLI bootstraps WordPress on its own. You will need to contact WP CLI developers or those familiar with it however, as WP CLI specific knowledge is out of scope here

131 questions

117 answers

7 comments

378 users

Welcome to Todayask Q&A, where you can ask questions and receive answers from other members of the community.
...