pmpro_next_payment

The Paid Memberships Pro pmpro next payment function.

Description

pmpro_next_payment( (constant) $user_id = NULL, (string) $order_status = 'success', (string) $format = 'timestamp' ); 

Parameters (3)

0. $user_id — Optional. (constant) => NULL
The user id.
1. $order_status — Optional. (string) => 'success'
The order status.
2. $format — Optional. (string) => 'timestamp'
The format.

Usage

  1. if ( !function_exists( 'pmpro_next_payment' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/functions.php'; 
  3.  
  4. // The user id. 
  5. $user_id = NULL; 
  6.  
  7. // The order status. 
  8. $order_status = 'success'; 
  9.  
  10. // The format. 
  11. $format = 'timestamp'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pmpro_next_payment($user_id, $order_status, $format); 
  15.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_next_payment($user_id = NULL, $order_status = "success", $format = "timestamp") 
  2. global $wpdb, $current_user; 
  3. if(!$user_id) 
  4. $user_id = $current_user->ID; 
  5.  
  6. if(!$user_id) 
  7. $r = false; 
  8. else 
  9. //get last order 
  10. $order = new MemberOrder(); 
  11. $order->getLastMemberOrder($user_id, $order_status); 
  12.  
  13. //get current membership level 
  14. $level = pmpro_getMembershipLevelForUser($user_id); 
  15.  
  16. if(!empty($order) && !empty($order->id) && !empty($level) && !empty($level->id) && !empty($level->cycle_number)) 
  17. //last payment date 
  18. $lastdate = date_i18n("Y-m-d", $order->timestamp); 
  19.  
  20. //next payment date 
  21. $nextdate = $wpdb->get_var("SELECT UNIX_TIMESTAMP('" . $lastdate . "' + INTERVAL " . $level->cycle_number . " " . $level->cycle_period . ")"); 
  22.  
  23. $r = $nextdate; 
  24. else 
  25. //noorderor level found, or level was not recurring 
  26. $r = false; 
  27.  
  28. /** 
  29. * Filter the next payment date. 
  30. * @since 1.8.5 
  31. * @param mixed $r false or the next payment date timestamp 
  32. * @param int $user_id The user id to get the next payment date for 
  33. * @param string $order_status Status or array of statuses to find the lastorderbased on. 
  34. */ 
  35. $r = apply_filters('pmpro_next_payment', $r, $user_id, $order_status); 
  36.  
  37. //return in desired format 
  38. if($r === false) 
  39. return false; //always return false when no date found 
  40. elseif($format == "timestamp") 
  41. return $r; 
  42. elseif($format == "date_format") 
  43. return date_i18n(get_option('date_format'), $r); 
  44. else 
  45. return date_i18n($format, $r); //assume a PHP date format