pmpro_getCancellationRate

The Paid Memberships Pro pmpro getCancellationRate function.

Description

pmpro_getCancellationRate( $period, (string) $levels = 'all', (constant) $status = NULL ); 

Parameters (3)

0. $period
The period.
1. $levels — Optional. (string) => 'all'
The levels.
2. $status — Optional. (constant) => NULL
The status.

Usage

  1. if ( !function_exists( 'pmpro_getCancellationRate' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/adminpages/reports/memberships.php'; 
  3.  
  4. // The period. 
  5. $period = null; 
  6.  
  7. // The levels. 
  8. $levels = 'all'; 
  9.  
  10. // The status. 
  11. $status = NULL; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = pmpro_getCancellationRate($period, $levels, $status); 
  15.  

Defined (1)

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

/adminpages/reports/memberships.php  
  1. function pmpro_getCancellationRate($period, $levels = 'all', $status = NULL) 
  2. {  
  3. //make sure status is an array 
  4. if(!is_array($status)) 
  5. $status = array($status); 
  6.  
  7. //check for a transient 
  8. $cache = get_transient("pmpro_report_cancellation_rate"); 
  9. $hash = md5($period . $levels . implode('', $status)); 
  10. if(!empty($cache) && !empty($cache[$hash])) 
  11. return $cache[$hash]; 
  12.  
  13. $signups = pmpro_getSignups($period, $levels); 
  14. $cancellations = pmpro_getCancellations($period, $levels, $status); 
  15.  
  16. if(empty($signups)) 
  17. return false; 
  18.  
  19. $rate = number_format(($cancellations / $signups)*100, 2); 
  20.  
  21. //save in cache 
  22. if(!empty($cache) && !empty($cache[$period])) 
  23. $cache[$period][$levels] = $rate; 
  24. elseif(!empty($cache)) 
  25. $cache[$period] = array($levels => $rate); 
  26. else 
  27. $cache = array($period => array($levels => $rate)); 
  28.  
  29. set_transient("pmpro_report_cancellation_rate", $cache, 3600*24); 
  30.  
  31. return $rate;