pmpro_calculateRecurringRevenue

The Paid Memberships Pro pmpro calculateRecurringRevenue function.

Description

pmpro_calculateRecurringRevenue( $s, $l ); 

Parameters (2)

0. $s
The s.
1. $l
The l.

Usage

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

Defined (1)

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

/includes/functions.php  
  1. function pmpro_calculateRecurringRevenue($s, $l) 
  2. global $wpdb; 
  3.  
  4. //if we're limiting users by search 
  5. if($s || $l) 
  6. $user_ids_query = "AND user_id IN(SELECT u.ID FROM $wpdb->users u LEFT JOIN $wpdb->usermeta um ON u.ID = um.user_id LEFT JOIN $wpdb->pmpro_memberships_users mu ON u.ID = mu.user_id WHERE mu.status = 'active' "; 
  7. if($s) 
  8. $user_ids_query .= "AND (u.user_login LIKE '%" . esc_sql($s) . "%' OR u.user_email LIKE '%" . esc_sql($s) . "%' OR um.meta_value LIKE '%" . esc_sql($s) . "%') "; 
  9. if($l) 
  10. $user_ids_query .= "AND mu.membership_id = '" . esc_sql($l) . "' "; 
  11. $user_ids_query .= ")"; 
  12. else 
  13. $user_ids_query = ""; 
  14.  
  15. //4 queries to get annual earnings for each cycle period. currently ignoring trial periods and billing limits. 
  16. $sqlQuery = " 
  17. SELECT SUM((12/cycle_number)*billing_amount) FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND cycle_period = 'Month' AND cycle_number <> 12 $user_ids_query 
  18. UNION 
  19. SELECT SUM((365/cycle_number)*billing_amount) FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND cycle_period = 'Day' AND cycle_number <> 365 $user_ids_query 
  20. UNION 
  21. SELECT SUM((52/cycle_number)*billing_amount) FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND cycle_period = 'Week' AND cycle_number <> 52 $user_ids_query 
  22. UNION 
  23. SELECT SUM(billing_amount) FROM $wpdb->pmpro_memberships_users WHERE status = 'active' AND cycle_period = 'Year' $user_ids_query 
  24. "; 
  25.  
  26. $annual_revenues = $wpdb->get_col($sqlQuery); 
  27.  
  28. $total = 0; 
  29. foreach($annual_revenues as $r) 
  30. $total += $r; 
  31.  
  32. return $total;