getUserFromCustomerEvent

The Paid Memberships Pro getUserFromCustomerEvent function.

Description

getUserFromCustomerEvent( $pmpro_stripe_event, (constant) $status = false, (constant) $checkplan = true ); 

Parameters (3)

0. $pmpro_stripe_event
The pmpro stripe event.
1. $status — Optional. (constant) => false
The status.
2. $checkplan — Optional. (constant) => true
The checkplan.

Usage

  1. if ( !function_exists( 'getUserFromCustomerEvent' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/services/stripe-webhook.php'; 
  3.  
  4. // The pmpro stripe event. 
  5. $pmpro_stripe_event = null; 
  6.  
  7. // The status. 
  8. $status = false; 
  9.  
  10. // The checkplan. 
  11. $checkplan = true; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = getUserFromCustomerEvent($pmpro_stripe_event, $status, $checkplan); 
  15.  

Defined (1)

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

/services/stripe-webhook.php  
  1. function getUserFromCustomerEvent($pmpro_stripe_event, $status = false, $checkplan = true) 
  2. //pause here to give PMPro a chance to finish checkout 
  3.  
  4. global $wpdb; 
  5.  
  6. $customer_id = $pmpro_stripe_event->data->object->customer; 
  7. $subscription_id = $pmpro_stripe_event->data->object->id; 
  8. $plan_id = $pmpro_stripe_event->data->object->plan->id; 
  9.  
  10. //look up the order 
  11. $sqlQuery = "SELECT user_id FROM $wpdb->pmpro_membership_orders WHERE (subscription_transaction_id = '" . esc_sql($customer_id) . "' OR subscription_transaction_id = '" . esc_sql($subscription_id) . "') "; 
  12. if($status) 
  13. $sqlQuery .= " AND status='" . esc_sql($status) . "' "; 
  14. if($checkplan) 
  15. $sqlQuery .= " AND code='" . esc_sql($plan_id) . "' "; 
  16. $sqlQuery .= " LIMIT 1"; 
  17.  
  18. $user_id = $wpdb->get_var($sqlQuery); 
  19.  
  20. if(!empty($user_id)) 
  21. return get_userdata($user_id); 
  22. else 
  23. return false;