pmpro_calculateInitialPaymentRevenue

The Paid Memberships Pro pmpro calculateInitialPaymentRevenue function.

Description

pmpro_calculateInitialPaymentRevenue( (constant) $s = NULL, (constant) $l = NULL ); 

Parameters (2)

0. $s — Optional. (constant) => NULL
The s.
1. $l — Optional. (constant) => NULL
The l.

Usage

  1. if ( !function_exists( 'pmpro_calculateInitialPaymentRevenue' ) ) { 
  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_calculateInitialPaymentRevenue($s, $l); 
  12.  

Defined (1)

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

/includes/functions.php  
  1. function pmpro_calculateInitialPaymentRevenue($s = NULL, $l = NULL) 
  2. global $wpdb; 
  3.  
  4. //if we're limiting users by search 
  5. if($s || $l) 
  6. $user_ids_query = "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.  
  12. //query to sum initial payments 
  13. $sqlQuery = "SELECT SUM(initial_payment) FROM $wpdb->pmpro_memberships_users WHERE `status` = 'active' "; 
  14. if(!empty($user_ids_query)) 
  15. $sqlQuery .= "AND user_id IN(" . $user_ids_query . ") "; 
  16.  
  17. $total = $wpdb->get_var($sqlQuery); 
  18.  
  19. return (double)$total;