pmpro_getSignups

The Paid Memberships Pro pmpro getSignups function.

Description

pmpro_getSignups( (constant) $period = false, (string) $levels = 'all' ); 

Parameters (2)

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

Usage

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

Defined (1)

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

/adminpages/reports/memberships.php  
  1. function pmpro_getSignups($period = false, $levels = 'all') 
  2. //check for a transient 
  3. $cache = get_transient( 'pmpro_report_memberships_signups' ); 
  4. if( ! empty( $cache ) && ! empty( $cache[$period] ) && ! empty( $cache[$period][$levels] ) ) 
  5. return $cache[$period][$levels]; 
  6.  
  7. //a sale is anorderwith status = success 
  8. if( $period == 'today' ) 
  9. $startdate = date_i18n(' Y-m-d' ); 
  10. elseif( $period == 'this month') 
  11. $startdate = date_i18n( 'Y-m' ) . '-01'; 
  12. elseif( $period == 'this year') 
  13. $startdate = date_i18n( 'Y' ) . '-01-01'; 
  14. else 
  15. $startdate = ''; 
  16.  
  17.  
  18. //build query 
  19. global $wpdb; 
  20.  
  21. $sqlQuery = "SELECT COUNT(DISTINCT user_id) FROM $wpdb->pmpro_memberships_users WHERE startdate >= '" . $startdate . "' "; 
  22.  
  23. //restrict by level 
  24. if(!empty($levels) && $levels != 'all') 
  25. $sqlQuery .= "AND membership_id IN(" . $levels . ") "; 
  26.  
  27. $signups = $wpdb->get_var($sqlQuery); 
  28.  
  29. //save in cache 
  30. if(!empty($cache) && !empty($cache[$period])) 
  31. $cache[$period][$levels] = $signups; 
  32. elseif(!empty($cache)) 
  33. $cache[$period] = array($levels => $signups); 
  34. else 
  35. $cache = array($period => array($levels => $signups)); 
  36.  
  37. set_transient("pmpro_report_memberships_signups", $cache, 3600*24); 
  38.  
  39. return $signups;