pmpro_ipnhandler_level_extend_memberships

Same thing as above but when processed by the ipnhandler for PayPal standard.

Description

pmpro_ipnhandler_level_extend_memberships( $level, $user_id ); 

Parameters (2)

0. $level
The level.
1. $user_id
The user id.

Usage

  1. if ( !function_exists( 'pmpro_ipnhandler_level_extend_memberships' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/filters.php'; 
  3.  
  4. // The level. 
  5. $level = null; 
  6.  
  7. // The user id. 
  8. $user_id = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pmpro_ipnhandler_level_extend_memberships($level, $user_id); 
  12.  

Defined (1)

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

/includes/filters.php  
  1. function pmpro_ipnhandler_level_extend_memberships($level, $user_id) 
  2. {  
  3. global $pmpro_msg, $pmpro_msgt; 
  4.  
  5. //does this level expire? are they an existing user of this level? 
  6. if(!empty($level) && !empty($level->expiration_number) && pmpro_hasMembershipLevel($level->id, $user_id)) 
  7. //get the current enddate of their membership 
  8. $user_level = pmpro_getMembershipLevelForUser($user_id);  
  9. $expiration_date = $user_level->enddate; 
  10.  
  11. //calculate days left 
  12. $todays_date = current_time('timestamp'); 
  13. $time_left = $expiration_date - $todays_date; 
  14.  
  15. //time left? 
  16. if($time_left > 0) 
  17. //convert to days and add to the expiration date (assumes expiration was 1 year) 
  18. $days_left = floor($time_left/(60*60*24)); 
  19.  
  20. //figure out days based on period 
  21. if($level->expiration_period == "Day") 
  22. $total_days = $days_left + $level->expiration_number; 
  23. elseif($level->expiration_period == "Week") 
  24. $total_days = $days_left + $level->expiration_number * 7; 
  25. elseif($level->expiration_period == "Month") 
  26. $total_days = $days_left + $level->expiration_number * 30; 
  27. elseif($level->expiration_period == "Year") 
  28. $total_days = $days_left + $level->expiration_number * 365; 
  29.  
  30. //update number and period 
  31. $level->expiration_number = $total_days; 
  32. $level->expiration_period = "Day"; 
  33.  
  34. return $level;