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. 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.

Check a User’s Membership Level: pmpro.getMembershipLevelForUser

The first XML-RPC method we support allows you to return the membership level for a specific user. The call requires three arguments:

  • username: a username for an Administrator-role user that has the pmpro_xmlrpc capability in the WordPress site.

  • password: the password for this Administrator user account.

  • user_id: the ID of the user whose membership level you want to check.

If the method is successful in communicating with your site, you can expect a return value of false if the user_id is not a member or an array containing the membership level values for member. If you do not pass a user_id with your request, the method will return data for the user for the included username argument.

Check a User’s Access to a Post: pmpro.hasMembershipAccess

The second method supported will allow you to check if a user has access to a specific post. The call requires five arguments:

    • username: a username for an Administrator-role user that has the pmpro_xmlrpc capability in the WordPress site
    • password: the password for this Administrator user account.
    • post_id: the ID of the post you are checking access for.
    • user_id: the ID of the user whose membership level you want to check.
    • return_membership_levels: set to true or false depending on whether you want to return the levels required for the tested post.

    If the method is successful in communicating with your site, you can expect a return value of true or false, confirming or denying that the user has access to that piece of content. If return_membership_levels is set to true, the call will instead return an array whose first value is true or false (based on the user’s access) and a second value containing an array of membership levels that have access to that post. If you do not pass a user_id with your request, the method will return data for the user for the included username argument.

    These methods are defined in the includes/xmlrpc.php file of the plugin.

    Sample Using the PMPro XML-RPC Methods

    This example can be loaded into the codebase of a separate WordPress site and will use the XML-RPC client bundled with WordPress to access the membership level data for a user on a different system. This is a bare bones example. A real life example might use the wp.getUser method built into WordPress to get a specific user’s ID based on a given email address and then use that user ID in the call to pmpro.getMembershipLevelForUser.

    You can write a similar call for communicating between your WordPress site and a .NET environment, an IOS or Android App, and more.

    For more information on the XML-RPC WordPress API, see: http://codex.wordpress.org/XML-RPC_WordPress_API.

    Was this article helpful?
    YesNo