If you’re reading this post, you probably already know what an API is, but just in case: Application Programming Interfaces—or APIs—are what enable communication between two or more different applications.

For example, there are several APIs that enable plugins like Paid Memberships Pro to “talk” to WordPress. In other words: APIs make integrations possible.

There are four types of API:

  • Websocket API

Paid Memberships Pro currently offers support for two of the APIs available in WordPress:

  • The REST API method
  • The XML-RPC method

This post provides a high-level overview of the endpoints available in each method, as well as a code recipe to demonstrate how developers can build their own basic API for membership data.

Banner Image Interacting with Paid Memberships Pro Through APIs

Using the WordPress REST API with Paid Memberships Pro

PMPro offers three WordPress REST API methods. The REST API uses JSON objects to send and receive data in your WordPress site. Check out the REST API Handbook for more information about using this API to interact with your WordPress site.

The three methods available in PMPro include pmpro_rest_api_get_permissions_check, pmpro_rest_api_get_user_level, and pmpro_rest_api_get_has_membership_access.

Read the REST API Documentation

XML-RPC Methods Available in Paid Memberships Pro

There are two XML-RPC methods available in PMPro that extend upon WordPress’ support for this API. You can read more about XML-RPC support in the WordPress Codex here.

The two methods available in PMPro include pmpro.getMembershipLevelForUser and pmpro.hasMembershipAccess. To use either method, you must authenticate the request with a username and password for an Administrator-role user that has the pmpro_xmlrpc capability in the WordPress site.

Read the XML-RPC Documentation

How to Build a Simple RESTful API to get PMPro Data

As an alternative to using these built-in API methods, you can build your own RESTful scripts to return specific data when specific parameters are passed into a WordPress URL.

This method is less secure since there is no user authentication, but it also doesn’t require you to save a username and password in plaintext in a different system that might be used to access parts of your WordPress system you didn’t intend to make public. In general, more measures should be made to make these APIs secure when using them on live sites.

This example that sets up a URL (/?verify=email@domain.com&secret=SOMESECRETHERE) your app can hit and receive a JSON encoded array of membership level data returned for the specified user. This is very similar to the pmpro.getMembershipLevelForUser XML-RPC example above.

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Maximum Flexibility

One of the benefits of open-source software is the amount of flexibility it allows, especially when it comes to integrating with other software like WordPress. Paid Memberships Pro was built “The WordPress Way” and is 100% GPL, which means more integrations and less compatibility problems.

Download PMPro for free to start exploring all of the ways you can build and customize a truly robust membership site.

Was this article helpful?