• Stars
    star
    150
  • Rank 247,323 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 9 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

wp-cli/restful

Unlock the potential of the WP REST API at the command line.

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 RESTful WP-CLI requires the latest nightly build of WP-CLI, which you can install with wp cli update --nightly.

Initial development was backed by a Kickstarter project. This project will evolve alongside the WP REST API's evolution in WordPress core.

Build Status

Quick links: Using | Installing | Contributing | Support

Using

RESTful WP-CLI makes WP REST API endpoints available as WP-CLI commands.

As WordPress becomes more of an application framework embedded into the web, RESTful WP-CLI enables WP-CLI users to interact with a given WordPress install through the higher-level, self-expressed abstraction of how WordPress understands itself. For instance, on an eCommerce website, instead of having to know data is stored as wp post list --post_type=edd_product, RESTful WP-CLI exposes the properly-modeled data at wp rest product list.

Here's an overview of how RESTful WP-CLI works, in two parts.

1. Auto-discovers WP REST API endpoints from any WordPress site running WordPress 4.7 or higher

Target a specific WordPress install with --path=<path>, --ssh=<host>, or --http=<domain>:

# The `--path=<path>` global parameter tells WP-CLI to interact with a WordPress install at a given path.
# Because this is a stock WordPress install, you see the posts, pages, and other resources you'd expect to see.
$ wp --path=/srv/www/wordpress-develop.dev/src rest
usage: wp rest attachment <command>
   or: wp rest category <command>
   or: wp rest comment <command>
   or: wp rest page <command>
   or: wp rest page-revision <command>
   or: wp rest post <command>
   or: wp rest post-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>

# The `--http=<domain>` global parameter tells WP-CLI to auto-discover endpoints over HTTP.
# Because Wired has some custom post types, they're automatically registered as WP-CLI commands.
$ wp --http=www.wired.com rest
usage: wp rest attachment <command>
   or: wp rest category <command>
   or: wp rest comment <command>
   or: wp rest liveblog <command>
   or: wp rest liveblog-revision <command>
   or: wp rest page <command>
   or: wp rest page-revision <command>
   or: wp rest podcast <command>
   or: wp rest post <command>
   or: wp rest post-revision <command>
   or: wp rest series <command>
   or: wp rest slack-channel <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>
   or: wp rest video <command>

# The `--ssh=<host>` global parameter proxies command execution to a remote WordPress install.
# Because runcommand has a completely custom data model, you can only interact with commands, excerpts, and sparks.
$ wp --ssh=runcommand.io rest
usage: wp rest command <command>
   or: wp rest excerpt <command>
   or: wp rest spark <command>

2. Registers WP-CLI commands for the resource endpoints it understands, in the wp rest namespace.

In addition to the standard list, get, create, update and delete commands, RESTful WP-CLI also registers commands for higher-level operations like edit, generate and diff.

# In this example, `@wpdev` is a WP-CLI alias to `--path=/srv/www/wordpress-develop.dev/src`.
$ wp @wpdev rest user
usage: wp rest user create --username=<username> [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] --email=<email> [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] --password=<password> [--capabilities=<capabilities>] [--porcelain]
   or: wp rest user delete <id> [--force=<force>] [--reassign=<reassign>] [--porcelain]
   or: wp rest user diff <alias> [<resource>] [--fields=<fields>]
   or: wp rest user edit <id>
   or: wp rest user generate [--count=<count>] [--format=<format>] --username=<username> [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] --email=<email> [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] --password=<password> [--capabilities=<capabilities>] [--porcelain]
   or: wp rest user get <id> [--context=<context>] [--fields=<fields>] [--field=<field>] [--format=<format>]
   or: wp rest user list [--context=<context>] [--page=<page>] [--per_page=<per_page>] [--search=<search>] [--exclude=<exclude>] [--include=<include>] [--offset=<offset>] [--order=<order>] [--orderby=<orderby>] [--slug=<slug>] [--roles=<roles>] [--fields=<fields>] [--field=<field>] [--format=<format>]
   or: wp rest user update <id> [--username=<username>] [--name=<name>] [--first_name=<first_name>] [--last_name=<last_name>] [--email=<email>] [--url=<url>] [--description=<description>] [--nickname=<nickname>] [--slug=<slug>] [--roles=<roles>] [--password=<password>] [--capabilities=<capabilities>] [--porcelain]

# Use `wp rest * edit` to open an existing item in the editor.
$ wp rest category edit 1 --user=daniel
---
description:
name: Uncategorized
slug: uncategorized
parent: 0

# Use `wp rest * generate` to generate dummy content.
$ wp @wpdev rest post generate --count=50 --title="Test Post" --user=daniel
Generating items  100% [==============================================] 0:01 / 0:02

# Use `wp rest * diff` to diff a resource or collection of resources between environments.
$ wp @dev-rest rest command diff @prod-rest find-unused-themes --fields=title
(-) http://runcommand.dev/api/ (+) https://runcommand.io/api/
  command:
  + title: find-unused-themes

If WP-CLI is operating directly against a WordPress install, you can use the --debug flag to track the number of queries and total execution time. This can be useful for measuring and profiling API requests.

$ wp rest category list --debug
Debug (rest): REST command executed 3 queries in 0.000311 seconds. Use --debug=rest to see all queries. (1.118s)
+---------------+
| name          |
+---------------+
| Test Category |
| Uncategorized |
+---------------+

There are many things RESTful WP-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

Installing this package requires WP-CLI 1.3.0-alpha or greater. Update to the latest nightly release with wp cli update --nightly.

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

Contributing

We appreciate you taking the initiative to contribute to this project.

Contributing isn’t limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

For a more thorough introduction, check out WP-CLI's guide to contributing. This package follows those policy and guidelines.

Reporting a bug

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should search existing issues to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please create a new issue. Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, review our bug report documentation.

Creating a pull request

Want to contribute a new feature? Please first open a new issue to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, please follow our guidelines for creating a pull request to make sure it's a pleasant experience. See "Setting up" for details specific to working on this package locally.

Support

GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

This README.md is generated dynamically from the project's codebase using wp scaffold package-readme (doc). To suggest changes, please submit a pull request against the corresponding part of the codebase.

More Repositories

1

wp-cli

⚙️ WP-CLI framework
PHP
4,866
star
2

php-cli-tools

A collection of tools to help with PHP command line utilities
PHP
672
star
3

profile-command

Quickly identify what's slow with WordPress
PHP
270
star
4

handbook

📖 Complete documentation for WP-CLI
PHP
189
star
5

scaffold-command

Generates code for post types, taxonomies, blocks, plugins, child themes, etc.
Gherkin
165
star
6

doctor-command

Diagnose problems within WordPress by running a series of checks for symptoms
Gherkin
145
star
7

sample-plugin

Example plugin, generated using `wp scaffold plugin sample-plugin`
Shell
106
star
8

entity-command

Manage WordPress comments, menus, options, posts, sites, terms, and users.
PHP
100
star
9

i18n-command

Provides internationalization tools for WordPress projects.
Gherkin
96
star
10

extension-command

Manages plugins and themes, including installs, activations, and updates.
PHP
88
star
11

wp-cli-bundle

📦 WP-CLI package that bundles the framework with a set of common commands
Gherkin
84
star
12

wp-config-transformer

Programmatically edit a wp-config.php file
PHP
80
star
13

db-command

Performs basic database operations using credentials stored in wp-config.php.
PHP
71
star
14

scaffold-package-command

Scaffolds WP-CLI commands with functional tests, full README.md, and more.
Gherkin
69
star
15

server-command

Launches PHP's built-in web server for a specific WordPress installation.
PHP
67
star
16

wp-super-cache-cli

A CLI interface for the WP Super Cache plugin
PHP
58
star
17

search-replace-command

Searches/replaces strings in the database.
Gherkin
57
star
18

core-command

Downloads, installs, updates, and manages a WordPress installation.
Gherkin
49
star
19

dist-archive-command

Create a distribution .zip or .tar.gz based on a plugin or theme's .distignore file
Gherkin
47
star
20

media-command

Imports files as attachments, regenerates thumbnails, or lists registered image sizes.
Gherkin
44
star
21

ideas

💡 Ideas and feature requests are collected here
40
star
22

wp-cli-tests

WP-CLI testing framework
PHP
39
star
23

config-command

Generates and reads the wp-config.php file.
Gherkin
38
star
24

wp-cli-dev

🛠 WP-CLI development environment that allows for easy development across all packages
PHP
36
star
25

builds

Phar, Debian, and RPM builds of WP-CLI
36
star
26

package-index

A list of packages containing WP-CLI commands
Twig
31
star
27

checksum-command

Verifies file integrity by comparing to published checksums.
PHP
31
star
28

cron-command

Tests, runs, and deletes WP-Cron events; manages WP-Cron schedules.
PHP
31
star
29

wp-cli.github.com

wp-cli.org website
CSS
24
star
30

shell-command

Opens an interactive PHP console for running and testing PHP code.
PHP
20
star
31

import-command

Imports content from a given WXR file.
PHP
20
star
32

rewrite-command

Lists or flushes the site's rewrite rules, updates the permalink structure.
PHP
20
star
33

google-sitemap-generator-cli

A CLI interface for the Google Sitemap Generator plugin
Gherkin
18
star
34

package-command

Lists, installs, and removes WP-CLI packages.
PHP
17
star
35

find-command

Find WordPress installations on the filesystem
PHP
16
star
36

admin-command

Open /wp-admin/ in a browser
PHP
15
star
37

cache-command

Manages object and transient caches.
PHP
15
star
38

dash-docset-generator

WP-CLI Dash docset generator
PHP
14
star
39

language-command

Installs, activates, and manages language packs.
PHP
13
star
40

export-command

Exports WordPress content to a WXR file.
PHP
12
star
41

super-admin-command

Lists, adds, or removes super admin users on a multisite installation.
Gherkin
11
star
42

maintenance-mode-command

Activates, deactivates or checks the status of the maintenance mode of a site.
PHP
9
star
43

eval-command

Executes arbitrary PHP code or files.
Gherkin
8
star
44

embed-command

Inspects oEmbed providers, clears embed cache, and more.
Gherkin
7
star
45

.github

🌐 Centralized community health files for all repositories
6
star
46

widget-command

Adds, moves, and removes widgets; lists sidebars.
PHP
5
star
47

role-command

Adds, removes, lists, and resets roles and capabilities.
PHP
5
star
48

automated-tests

Runs the entire test suite on a regular basis
Shell
5
star
49

autoload-splitter

PHP
4
star
50

wp-cli-shim

This repository provides easy way to install WP-CLI without the risk of conflicting dependencies.
3
star
51

dashboard

Dashboard for WP-CLI contributors
HTML
2
star
52

wp-cli-roadmap

Roadmap planning for WP-CLI
2
star
53

sql-transform

PHP
1
star
54

getting-started-workshop

Dockerfile
1
star
55

reusable-workflow-test

Launches PHP's built-in web server for a specific WordPress installation.
PHP
1
star
56

rpm-build

Builds a RPM of the latest stable WP-CLI release
1
star
57

deb-build

1
star