Script integration with WordPress sites via the WordPress XML-RPC API. Currently this object has one runMethod function which can be used to call any method available in the XML-RPC interface.

The WordPress API offers access to a wide variety of functions, including posting, but also retrieving information about categories and tags, or reading posts contents.

Drafts WordPress object simplifies working with the XML-RPC interface by accepting input parameters as Javascript objects and converting them to the require XML to make requests of the WordPress site. Similarly, it converts to XML returned by WordPress to Javascript objects. Otherwise it is an exact passthrough, so the WordPress API reference should be used to determine method names (e.g. wp.newPost, wp.getTaxonomies) available, the appropriate parameters to send.

The WordPress XML-RPC API authenticates via username and password, so it is highly recommended you interact only over HTTPS secure connections, and use Credential objects to store host/username/password values, rather than hard-coding them in actions.

Example

// setup values to use in post
let title = "Title of Post"
let body = "Body of Post"

// create credentials for site
let cred = Credential.createWithHostUsernamePassword("WordPress", "WordPress * credentials. Include full URL (with http://) of the home page of your WordPress * site in the host field.");
cred.authorize();

// create WordPress object and make request
let wp = WordPress.create(cred.getValue("host"), 1, "", "");
let method = "wp.newPost"
let params = [
1, // blog_id, in most cases just use 1
cred.getValue("username"),
cred.getValue("password"),
{
"post_title": title,
"post_content": body,
"post_status": "draft",
"terms_names" : { // assign categories and tags
"category" : ["Cat1", "BAD"],
"post_tag" : ["Test1", "NOT-TAG"]
}
}
];

let response = wp.runMethod(method, params);
if (response.success) {
let params = response.params;
console.log("Create WordPress post id: " + params[0]);
}
else {
console.log("HTTP Status: " + response.statusCode);
console.log("Fault: " + response.error);
context.fail();
}

Hierarchy

  • WordPress

Constructors

  • Create new instance

    Parameters

    • siteURL: string

      This should be the full URL to the home page of the WordPress site. e.g. https://mysite.com or https://mysite.com/blog/.

    • blogId: string

      For most WordPress installations, use 1.

    • Optional username: string

      Username to login to the WordPress site. Optional if only using runMethod, as credentials will be required directly in parameters for those calls.

    • Optional password: string

      Password to login to the WordPress site. Optional if only using runMethod, as credentials will be required directly in parameters for those calls.

    Returns WordPress

Methods

  • Returns object[]

  • Parameters

    • postId: string

    Returns object

  • Returns object[]

  • Parameters

    • Optional filter: any

    Returns object[]

  • Returns object[]

  • Returns object[]

  • Parameters

    • Optional taxonomy: string

    Returns object

  • Parameters

    • Optional taxonomy: string
    • Optional filter: any

    Returns object[]

  • Parameters

    • content: string

    Returns string

  • Run an XML-RPC API method on a WordPress site. Any method name supported by the WordPress XML-RPC API can be used, as long as the authentication information provided has appropriate permissions on the site.

    Parameters

    • methodName: string

      The method name as documented in the WordPress XML-RPC API, for example wp.newPost to create a new post.

    • parameters: any[]

      Parameters should be a Javascript array of parameters for the method being used. These vary depending on the method and should follow the documentation provided by WordPress.

    Returns XMLRPCResponse

  • Create new instance

    Parameters

    • siteURL: string

      This should be the full URL to the home page of the WordPress site. e.g. https://mysite.com or https://mysite.com/blog/.

    • blogId: string

      For most WordPress installations, use 1.

    • Optional username: string

      Username to login to the WordPress site. Optional if only using runMethod, as credentials will be required directly in parameters for those calls.

    • Optional password: string

      Password to login to the WordPress site. Optional if only using runMethod, as credentials will be required directly in parameters for those calls.

    Returns WordPress

Generated using TypeDoc