NAME
wp-xmlrpc - A thin layer of CLI over WordPress XML-RPC API
VERSION
This document describes version 0.003 of wp-xmlrpc (from Perl distribution App-wp-xmlrpc), released on 2017-04-24.
SYNOPSIS
In ~/wp-xmlrpc.conf
, put your API credentials:
proxy=https://YOURBLOGNAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
Then:
% wp-xmlrpc wp.getPost 13
You can also put multiple credentials in the config file via profiles:
[profile=blog1]
proxy=https://BLOG1NAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
[profile=blog2]
proxy=https://BLOG2NAME.wordpress.com/xmlrpc.php
username=YOURUSERNAME
password=YOURPASSWORD
then:
% wp-xmlrpc --config-profile blog1 wp.getPost 13
Some of the functions:
% wp-xmlrpc wp.getPosts ;# list all posts
% wp-xmlrpc wp.newPost '{"post_content":"This is a test blog post"}' ;# by default will create an untitled blog post with status=draft
% wp-xmlrpc wp.newPost '{"post_content":"This is a test blog post", "post_status":"publish", "post_title":"Some title"}' ;# set title & status
% wp-xmlrpc wp.editPost 13 '{"status":"draft"}'
% wp-xmlrpc wp.deletePost 13
% wp-xmlrpc wp.getTaxonomies
% wp-xmlrpc wp.getTaxonomy category
% wp-xmlrpc wp.getTaxonomy post_tag
% wp-xmlrpc wp.getTaxonomy post_format
% wp-xmlrpc wp.getTaxonomy mentions
% wp-xmlrpc wp.getTerms category ;# get terms (i.e. in this case list of categories)
% wp-xmlrpc wp.getTerm category 2342 ;# get a specific category by ID
% wp-xmlrpc wp.getTerm tag 423 ;# get a specific tag by ID
% wp-xmlrpc wp.newTerm '{"taxonomy":"tag", "name":"tag3"}' ;# create a new tag
% wp-xmlrpc wp.newTerm '{"taxonomy":"category", "name":"cat2", "description":"Second category", "parent":2342}' ;# create a new category, with description and parent ID
% wp-xmlrpc wp.editTerm 2345 '{"description":"New description"}' ;# create a category's description
% wp-xmlrpc wp.deleteTerm 2345
% wp-xmlrpc wp.getComments ;# list comments
% wp-xmlrpc wp.getCommentCount 13 ;# get number of comments for a post
% wp-xmlrpc wp.getComment 9983 ;# get a comment by ID
% wp-xmlrpc wp.getOptions ;# get all options
% wp-xmlrpc wp.getOptions '["blog_title","blog_tagline"]' ;# get specified options only
% wp-xmlrpc wp.setOptions '{"blog_title":"New title", "blog_tagline":"New tagline"}'
% wp-xmlrpc wp.getProfile
% wp-xmlrpc wp.editProfile '{"bio":"Blah blah blah"}'
DESCRIPTION
This script is a thin layer of CLI over WordPress XML-RPC API, mainly for testing/debugging. Each CLI subcommand is for calling API method of the same name. If an argument starts with {
it will be assumed as a JSON-encoded hash and will be decoded. If an argument starts with [
it will be assumed as a JSON-encoded array and will be decoded.
SUBCOMMANDS
wp.deleteComment
wp.deletePost
wp.deleteTerm
wp.editComment
wp.editPost
wp.editProfile
wp.editTerm
wp.getAuthors
wp.getComment
wp.getCommentCount
wp.getCommentStatusList
wp.getComments
wp.getMediaItem
wp.getMediaLibrary
wp.getOptions
wp.getPost
wp.getPostFormats
wp.getPostStatusList
wp.getPostType
wp.getPostTypes
wp.getPosts
wp.getProfile
wp.getTaxonomies
wp.getTaxonomy
wp.getTerm
wp.getTerms
wp.getUser
wp.getUsers
wp.getUsersBlogs
wp.newComment
wp.newPost
wp.newTerm
wp.setOptions
OPTIONS
*
marks required options.
Common options
- --blog-id=i
-
Default value:
1
- --config-path=filename
-
Set path to configuration file.
Can be specified multiple times.
- --config-profile=s
-
Set configuration profile to use.
- --format=s
-
Choose output format, e.g. json, text.
Default value:
undef
- --help, -h, -?
-
Display help message and exit.
- --json
-
Set output format to json.
- --naked-res
-
When outputing as JSON, strip result envelope.
Default value:
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use `--naked-res` so you just get:
[1,2,3]
- --no-config
-
Do not use any configuration file.
- --no-env
-
Do not read environment for default options.
- --password=s*, -p
- --proxy=s*
- --subcommands
-
List available subcommands.
- --username=s*, -u
- --version, -v
-
Display program's version and exit.
Options for subcommand wp.deleteComment
Options for subcommand wp.deletePost
Options for subcommand wp.deleteTerm
Options for subcommand wp.editComment
Options for subcommand wp.editPost
Options for subcommand wp.editProfile
Options for subcommand wp.editTerm
Options for subcommand wp.getComment
Options for subcommand wp.getCommentCount
Options for subcommand wp.getComments
Options for subcommand wp.getMediaItem
Options for subcommand wp.getMediaLibrary
Options for subcommand wp.getOptions
Options for subcommand wp.getPost
Options for subcommand wp.getPostFormats
Options for subcommand wp.getPostType
Options for subcommand wp.getPostTypes
Options for subcommand wp.getPosts
Options for subcommand wp.getProfile
Options for subcommand wp.getTaxonomy
Options for subcommand wp.getTerm
Options for subcommand wp.getTerms
Options for subcommand wp.getUser
Options for subcommand wp.getUsers
Options for subcommand wp.getUsersBlogs
Options for subcommand wp.newComment
Options for subcommand wp.newPost
Options for subcommand wp.newTerm
Options for subcommand wp.setOptions
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C wp-xmlrpc wp-xmlrpc
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install shcompgen which allows you to activate completion scripts for several kinds of scripts on multiple shells. Some CPAN distributions (those that are built with Dist::Zilla::Plugin::GenShellCompletion) will even automatically enable shell completion for their included scripts (using shcompgen) at installation time, so you can immediately have tab completion.
tcsh
To activate tcsh completion for this script, put:
complete wp-xmlrpc 'p/*/`wp-xmlrpc`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
other shells
For fish and zsh, install shcompgen as described above.
CONFIGURATION FILE
This script can read configuration files. Configuration files are in the format of IOD, which is basically INI with some extra features.
By default, these names are searched for configuration filenames (can be changed using --config-path
): ~/.config/wp-xmlrpc.conf, ~/wp-xmlrpc.conf, or /etc/wp-xmlrpc.conf.
All found files will be read and merged.
To disable searching for configuration files, pass --no-config
.
To put configuration for a certain subcommand only, use a section name like [subcommand=NAME]
or [SOMESECTION subcommand=NAME]
.
You can put multiple profiles in a single file by using section names like [profile=SOMENAME]
or [SOMESECTION profile=SOMENAME]
or [subcommand=SUBCOMMAND_NAME profile=SOMENAME]
or [SOMESECTION subcommand=SUBCOMMAND_NAME profile=SOMENAME]
. Those sections will only be read if you specify the matching --config-profile SOMENAME
.
You can also put configuration for multiple programs inside a single file, and use filter program=NAME
in section names, e.g. [program=NAME ...]
or [SOMESECTION program=NAME]
. The section will then only be used when the reading program matches.
Finally, you can filter a section by environment variable using the filter env=CONDITION
in section names. For example if you only want a section to be read if a certain environment variable is true: [env=SOMEVAR ...]
or [SOMESECTION env=SOMEVAR ...]
. If you only want a section to be read when the value of an environment variable has value equals something: [env=HOSTNAME=blink ...]
or [SOMESECTION env=HOSTNAME=blink ...]
. If you only want a section to be read when the value of an environment variable does not equal something: [env=HOSTNAME!=blink ...]
or [SOMESECTION env=HOSTNAME!=blink ...]
. If you only want a section to be read when an environment variable contains something: [env=HOSTNAME*=server ...]
or [SOMESECTION env=HOSTNAME*=server ...]
. Note that currently due to simplistic parsing, there must not be any whitespace in the value being compared because it marks the beginning of a new section filter or section name.
List of available configuration parameters:
Common for all subcommands
blog_id (see --blog-id)
format (see --format)
naked_res (see --naked-res)
password (see --password)
proxy (see --proxy)
username (see --username)
Configuration for subcommand 'wp.deleteComment'
comment_id (see --comment-id)
Configuration for subcommand 'wp.deletePost'
post_id (see --post-id)
Configuration for subcommand 'wp.deleteTerm'
term_id (see --term-id)
Configuration for subcommand 'wp.editComment'
comment (see --comment)
comment_id (see --comment-id)
Configuration for subcommand 'wp.editPost'
content (see --content)
Configuration for subcommand 'wp.editProfile'
content (see --content)
Configuration for subcommand 'wp.editTerm'
content (see --content)
term_id (see --term-id)
Configuration for subcommand 'wp.getAuthors'
Configuration for subcommand 'wp.getComment'
comment_id (see --comment-id)
Configuration for subcommand 'wp.getCommentCount'
post_id (see --post-id)
Configuration for subcommand 'wp.getCommentStatusList'
Configuration for subcommand 'wp.getComments'
filter (see --filter)
Configuration for subcommand 'wp.getMediaItem'
attachment_id (see --attachment-id)
Configuration for subcommand 'wp.getMediaLibrary'
filter (see --filter)
Configuration for subcommand 'wp.getOptions'
options (see --options)
Configuration for subcommand 'wp.getPost'
fields (see --fields)
post_id (see --post-id)
Configuration for subcommand 'wp.getPostFormats'
filter (see --filter)
Configuration for subcommand 'wp.getPostStatusList'
Configuration for subcommand 'wp.getPostType'
fields (see --fields)
post_type_name (see --post-type-name)
Configuration for subcommand 'wp.getPostTypes'
fields (see --fields)
filter (see --filter)
Configuration for subcommand 'wp.getPosts'
filter (see --filter)
Configuration for subcommand 'wp.getProfile'
fields (see --fields)
Configuration for subcommand 'wp.getTaxonomies'
Configuration for subcommand 'wp.getTaxonomy'
taxonomy (see --taxonomy)
Configuration for subcommand 'wp.getTerm'
taxonomy (see --taxonomy)
term_id (see --term-id)
Configuration for subcommand 'wp.getTerms'
taxonomy (see --taxonomy)
Configuration for subcommand 'wp.getUser'
fields (see --fields)
user_id (see --user-id)
Configuration for subcommand 'wp.getUsers'
fields (see --fields)
Configuration for subcommand 'wp.getUsersBlogs'
isAdmin (see --isAdmin)
xmlrpc (see --xmlrpc)
Configuration for subcommand 'wp.newComment'
comment (see --comment)
post_id (see --post-id)
Configuration for subcommand 'wp.newPost'
content (see --content)
Configuration for subcommand 'wp.newTerm'
content (see --content)
Configuration for subcommand 'wp.setOptions'
options (see --options)
ENVIRONMENT
WP_XMLRPC_OPT => str
Specify additional command-line options.
FILES
~/.config/wp-xmlrpc.conf
~/wp-xmlrpc.conf
/etc/wp-xmlrpc.conf
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-wp-xmlrpc.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-wp-xmlrpc.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-wp-xmlrpc
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
SEE ALSO
API reference: https://codex.wordpress.org/XML-RPC_WordPress_API
wordpress-info, wordpress-upload-media, wordpress-upload-post from the WordPress::CLI distribution.
AUTHOR
perlancar <perlancar@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017, 2016 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.