Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kimcoleman/af286d76e0ed80e4732d624830ebaf4e to your computer and use it in GitHub Desktop.
Save kimcoleman/af286d76e0ed80e4732d624830ebaf4e to your computer and use it in GitHub Desktop.
Very basic custom RESTful API to check the membership level of a Paid Memberships Pro User
<?php
/**
* Call to http://yoursite.com/?verify=email@domain.com&secret=SOMESECRETHERE to check the membership level of a user.
*/
function my_init_pmpro_mini_api() {
if ( function_exists( 'pmpro_getMembershipLevelForUser' ) &&
! empty( $_REQUEST[ 'verify' ] ) &&
! empty( $_REQUEST[ 'secret' ] ) )
{
if ( $_REQUEST[ 'secret' ] != 'SOMESECRETHERE' ) {
wp_die( 'Invalid secret.' );
}
$user = get_user_by( 'email', str_replace( ' ', '+', ( $_REQUEST['verify'] ) ) ) ;
if ( empty( $user ) ) {
wp_die( 'User not found.' );
}
$membership_level = pmpro_getMembershipLevelForUser( $user->ID );
if ( empty( $membership_level ) ) {
die( '0' );
}
//If User and membership level found, output json encoded membership level info.
echo json_encode( $membership_level );
exit;
}
}
add_action( 'init', 'my_init_pmpro_mini_api' );
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Interacting with Paid Memberships Pro Through APIs" at Paid Memberships Pro here: https://www.paidmembershipspro.com/interacting-with-paid-memberships-pro-through-apis/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment