Skip to content
/ restful Public

Unlocking the potential of the WP REST API at the command line

License

Notifications You must be signed in to change notification settings

wp-cli/restful

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

wp-rest-cli

Unlock the potential of the WP REST API at the command line. Project backed by Pressed, Chris Lema, Human Made, Pagely, Pantheon and many others. Learn more →

Warning: This project is at a very early stage. Treat it as an experiment, and understand that breaking changes will be made without warning. The sky may also fall on your head. Using wp-rest-cli requires the latest nightly build of WP-CLI, which you can install with wp cli update --nightly.

Build Status

Quick links: Overview | Installing | Contributing

Overview

wp-rest-cli makes WP REST API endpoints available as WP-CLI commands. It does so by:

  • Auto-discovering WP REST API endpoints from any WordPress site running WordPress 4.4 or higher.
  • Registering WP-CLI commands for the endpoints it understands.

For example:

$ wp rest
usage: wp rest attachment <command>
   or: wp rest category <command>
   or: wp rest comment <command>
   or: wp rest meta <command>
   or: wp rest page <command>
   or: wp rest pages-revision <command>
   or: wp rest post <command>
   or: wp rest posts-revision <command>
   or: wp rest status <command>
   or: wp rest tag <command>
   or: wp rest taxonomy <command>
   or: wp rest type <command>
   or: wp rest user <command>

$ wp --http=demo.wp-api.org rest tag get 65 --format=json
{
  "id": 65,
  "link": "http://demo.wp-api.org/tag/dolor-in-sunt-placeat-molestiae-ipsam/",
  "name": "Dolor in sunt placeat molestiae ipsam",
  "slug": "dolor-in-sunt-placeat-molestiae-ipsam",
  "taxonomy": "post_tag"
}

Notice how you can use --http=<domain> to interact with a remote WordPress site. --http=<domain> must be supplied as the second argument to be used. Without it, wp-rest-cli will look for endpoints of a WordPress site in a directory specified by --path=<path> (or the current directory, if --path=<path isn't supplied).

There are many things wp-rest-cli can't yet do. Please review the issue backlog, and open a new issue if you can't find an exising issue for your topic.

Installing

wp-rest-cli requires the latest nightly version of WP-CLI. Update with wp cli update --nightly.

Once you've done so, you can install wp-rest-cli with wp package install wp-cli/restful.

wp-rest-cli also requires the latest WP REST API beta installed and activated on whichever WordPress you'd like to interact with. Older betas are unsupported — please keep up to date.

Contributing

Code and ideas are more than welcome. Please open an issue with questions, feedback, and violent dissent. Pull requests are expected to include test coverage.