Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test code for the XMLRPC methods added to Paid Memberships Pro in PMPro v2.0. Add this to your active theme's functions.php or a custom plugin, then navigate to /?rpctest=1.
/*
This code is just meant as a sample of how to use the new XMLRPC methods in PMPro.
Aftering adding this code, navigate to /?rpctest=1
*/
function xmlrpc_test()
{
if(!empty($_REQUEST['rpctest']) && current_user_can("manage_options"))
{
//load XMLRPC Client
include(ABSPATH . "/wp-includes/class-IXR.php");
$client = new IXR_Client(home_url('xmlrpc.php'));
//test values
$username = ""; //user login to use
$pass = ""; //pass of the admin user
$post_id = "1"; //a real post id
$user_id = "1"; //if different from the admin
//get membership level data for a user
$client->query('pmpro.getMembershipLevelForUser',$username,$pass,$user_id);
//output
echo "<pre>";
print_r($client->message);
echo "</pre>";
//does the user have access to post_id?
$client->query('pmpro.hasMembershipAccess',$username,$pass,$post_id,$user_id);
//output
echo "<pre>";
print_r($client->message);
echo "</pre>";
exit;
}
}
add_action("init", "xmlrpc_test");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment