pmpro_cron_credit_card_expiring_warnings

The Paid Memberships Pro pmpro cron credit card expiring warnings function.

Description

pmpro_cron_credit_card_expiring_warnings(); 

Usage

  1. if ( !function_exists( 'pmpro_cron_credit_card_expiring_warnings' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/scheduled/crons.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = pmpro_cron_credit_card_expiring_warnings(); 
  7.  

Defined (1)

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

/scheduled/crons.php  
  1. function pmpro_cron_credit_card_expiring_warnings() 
  2. global $wpdb; 
  3.  
  4. $next_month_date = date_i18n("Y-m-01", strtotime("+2 months", current_time("timestamp"))); 
  5.  
  6. $sqlQuery = "SELECT mu.user_id 
  7. FROM $wpdb->pmpro_memberships_users mu 
  8. LEFT JOIN $wpdb->usermeta um1 ON mu.user_id = um1.user_id 
  9. AND meta_key = 'pmpro_ExpirationMonth' 
  10. LEFT JOIN $wpdb->usermeta um2 ON mu.user_id = um2.user_id 
  11. AND um2.meta_key = 'pmpro_ExpirationYear' 
  12. LEFT JOIN $wpdb->usermeta um3 ON mu.user_id = um3.user_id 
  13. AND um3.meta_key = 'pmpro_credit_card_expiring_warning' 
  14. WHERE mu.status = 'active' 
  15. AND mu.cycle_number >0 
  16. AND CONCAT(um2.meta_value, '-', um1.meta_value, '-01') < '" . $next_month_date . "' 
  17. AND (um3.meta_value IS NULL OR CONCAT(um2.meta_value, '-', um1.meta_value, '-01') <> um3.meta_value) 
  18. "; 
  19.  
  20. if(defined('PMPRO_CRON_LIMIT')) 
  21. $sqlQuery .= " LIMIT " . PMPRO_CRON_LIMIT; 
  22.  
  23. $cc_expiring_user_ids = $wpdb->get_col($sqlQuery); 
  24.  
  25. if(!empty($cc_expiring_user_ids)) 
  26. require_once(ABSPATH . 'wp-includes/pluggable.php'); 
  27.  
  28. foreach($cc_expiring_user_ids as $user_id) 
  29. //get user 
  30. $euser = get_userdata($user_id); 
  31.  
  32. //make sure their level doesn't have a billing limit that's been reached 
  33. $euser->membership_level = pmpro_getMembershipLevelForUser($euser->ID); 
  34. if(!empty($euser->membership_level->billing_limit)) 
  35. /** 
  36. There is a billing limit on this level, skip for now. 
  37. We should figure out how to tell if the limit has been reached 
  38. and if not, email the user about the expiring credit card. 
  39. */ 
  40. continue; 
  41.  
  42. //make sure they are using a creditcardtype billing method for their current membership level (check the last order) 
  43. $last_order = new MemberOrder(); 
  44. $last_order->getLastMemberOrder($euser->ID); 
  45. if(empty($last_order->accountnumber) && 'XXXXXXXXXXXXXXXX' != $last_order->accountnumber) 
  46. continue; 
  47.  
  48. //okay send them an email 
  49. $send_email = apply_filters("pmpro_send_credit_card_expiring_email", true, $euser->user_id); 
  50.  
  51. if($send_email) 
  52. //send an email 
  53. $pmproemail = new PMProEmail(); 
  54. $pmproemail->sendCreditCardExpiringEmail($euser, $last_order); 
  55.  
  56. if(current_user_can('manage_options')) 
  57. printf(__("Creditcardexpiring email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email); 
  58. else 
  59. echo ". "; 
  60.  
  61. //update user meta so we don't email them again 
  62. update_user_meta($euser->ID, "pmpro_credit_card_expiring_warning", $euser->pmpro_ExpirationYear . "-" . $euser->pmpro_ExpirationMonth . "-01");