pmpro_xmlrpc_hasMembershipAccess

API method to check if a user has access to a certain post.

Description

pmpro_xmlrpc_hasMembershipAccess( $args ); 

Since v2.0

Parameters (1)

0. $args
The args.

Usage

  1. if ( !function_exists( 'pmpro_xmlrpc_hasMembershipAccess' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/xmlrpc.php'; 
  3.  
  4. // The args. 
  5. $args = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = pmpro_xmlrpc_hasMembershipAccess($args); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/xmlrpc.php  
  1. function pmpro_xmlrpc_hasMembershipAccess($args) 
  2. // Parse the arguments, assuming they're in the correct order 
  3. $username = $args[0]; 
  4. $password = $args[1]; 
  5. $post_id = $args[2]; //post id to check 
  6. $user_id = $args[3]; //optional user id passed in 
  7. $return_membership_levels = $args[4]; //option to also include an array of membership levels with access to the post 
  8.  
  9. global $wp_xmlrpc_server; 
  10.  
  11. // Let's run a check to see if credentials are okay 
  12. if ( !$user = $wp_xmlrpc_server->login($username, $password) ) { 
  13. return $wp_xmlrpc_server->error; 
  14.  
  15. // The user passed should be an admin or have the pmpro_xmlprc capability 
  16. if(!user_can($user->ID, "manage_options") && !user_can($user->ID, "pmpro_xmlrpc")) 
  17. return "ERROR: User does not have access to the PMPro XMLRPC methods."; 
  18.  
  19. // Default to logged in user if no user_id is given. 
  20. if(empty($user_id)) 
  21. {  
  22. $user_id = $user->ID; 
  23.  
  24. $has_access = pmpro_has_membership_access($post_id, $user_id, $return_membership_levels); 
  25.  
  26. return $has_access;