wac
wp-api-cli
npm i wp-api-cli
wac

wp-api-cli

CLI for WordPress.org REST API v2

by Thiago Negri

0.4.1 (see all)License:GPL-2.0TypeScript:Not Found
npm i wp-api-cli
Readme

CLI for WordPress.org REST API v2

Build status of master branch Code coverage of master branch Code climate of master branch Dependency status of master branch

CLI to help test-drive the WordPress.org REST API.

Installing

  1. WP-API v2 depends on the latest WordPress.org, so download it from Subversion.
  2. Install WP-API plugin from Git and activate it.
    • There are some fixes that I made concerning file uploads and missing metadata, consider using the branch 'tnegri' of my fork if the fixes are not already merged.
  3. Install Node.js.
  4. Install the latest published version of this CLI on your system: npm install --global wp-api-cli.
  5. Update CLI from API description: wp-api-cli update https://yoursite.com.

Authenticating with OAuth 1.0

  1. Install WP-API/OAuth1 from Git to support OAuth authentication, activate it.

  2. Install WP-CLI to generate OAuth keys.

  3. Go to your WordPress installation folder and create a new consumer key and secret for this CLI:

    wp oauth1 add
    
  4. Authenticate this CLI:

    wp-api-cli authenticate            \
        --oauth_key=CONSUMER_KEY       \
        --oauth_secret=CONSUMER_SECRET
    
  5. It will ask for an authorization token. Follow the steps on the browser, copy the authorization token and paste it on console.

  6. It will write the OAuth tokens to a file for further use -- this is a sensitive file, make sure to protect it!

  7. When you execute a command, the CLI will look for the file to grab the OAuth tokens, you may set a different file to use with the option --oauth_file.

  8. If you want to remove the OAuth tokens from the file system:

    wp-api-cli logout
    

Authenticating with HTTP Basic Auth

  1. Install WP-API/Basic-Auth from Git to support HTTP Basic Authentication, activate it.
  2. Use options --http_user and --http_pass with every request you make.

Commands

After installing the CLI, you need to update its definition:

wp-api-cli update https://example.com

After updating, ask for help to see everything available in your site:

wp-api-cli --help

Examples

Show all posts

$ wp-api-cli posts --table --project id,date,title

----------------------------------------------
 | id | date                | title         |
----------------------------------------------
 | 6  | 2015-08-22T20:27:32 | Hello, WP-API |
 | 1  | 2015-08-18T23:09:35 | Hello world!  |
----------------------------------------------

Show a specific post

$ wp-api-cli posts --yaml --id 6 --project id,date,title,content,comment_status

id: 6
date: '2015-08-22T20:27:32'
title:
  rendered: 'Hello, WP-API'
content:
  rendered: |
    <p>Hello, dear WP-API!</p>
comment_status: open

See docs/COMMANDS.md for a full documentation on commands.

Developers

This project is structured as follows:

  1. index.js is the entry point, it executes the main function defined in lib/wp-api-cli.js.
  2. lib/wp-api-cli.js wires everything up.
  3. lib/wp-api.js contains the class that communicates with the REST APIs.
  4. lib/modules.js loads all modules. A module is an object that provides the functionalities of the CLI.
  5. Files in lib/utils are utility functions to make coding easier.

If you want to create a new set of commands, drop a file in lib/modules and load it in modules.js. Full explanation in docs/MODULES.md.

Issues

Fixes

Features

Project Overview

Overview image of project files

Downloads/wk

38

GitHub Stars

12

LAST COMMIT

7yrs ago

MAINTAINERS

1

CONTRIBUTORS

1

OPEN ISSUES

4

OPEN PRs

0
VersionTagPublished
0.4.1
latest
7yrs ago
No alternatives found
No tutorials found
Add a tutorial