wp-cli-api

Notice: wp-cli-api is still beta software. Until a 1.0 release is made available there are manual steps required to install the software.

Seamlessly run WP-CLI commands on a remote server via the WordPress API

WP-CLI is an extremely useful tool for managing WordPress installs, but it requires you to invoke it on the same server where WordPress is installed. This means you have to ssh into the server, navigate to the install, and then run the command. It would be much more convenient if you could remain on your local shell and invoke WP-CLI remotely.

WP-CLI API operates against your WordPress’ API. Install the wp-cli-api plugin on the WordPress site you want to control, and install the api and/or yapi comamnds in WP-CLI on the computer you want to control remote sites with.

config.yml-based configuration and the yapi command

Assuming you have a clone of your WordPress install on your machine, add an api section to your wp-cli.yml config file. In this section you define the remote servers which host the other environments for your site, e.g. development, staging, production. Then you just invoke WP-CLI normally, but supply a host argument to the api command host you want to connect to http://livesite.com:

wp yapi production plugin status

The command and sub-command can be specified with positional parameters, but anything past that has to be passed as a string inside the --args option.

wp yapi production option get --args='siteurl'

One advantage of the config.yml approach is it’s independent of WordPress, so you can excute wp yapi from any working directory.

wp-config.php-based configuration and the api command

You can alternatively configure the command with wp-config.php from WordPress. To do this, you must run the wp api command from the WordPress installation directory. You must also install the wpConfigure plugin first. Then your wp-config.php file might look something like thiswp-config.php