pmpro_cron_expiration_warnings

The Paid Memberships Pro pmpro cron expiration warnings function.

Description

pmpro_cron_expiration_warnings(); 

Usage

  1. if ( !function_exists( 'pmpro_cron_expiration_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_expiration_warnings(); 
  7.  

Defined (1)

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

/scheduled/crons.php  
  1. function pmpro_cron_expiration_warnings() 
  2. global $wpdb; 
  3.  
  4. //make sure we only run once a day 
  5. $today = date_i18n("Y-m-d 00:00:00", current_time("timestamp")); 
  6.  
  7. $pmpro_email_days_before_expiration = apply_filters("pmpro_email_days_before_expiration", 7); 
  8.  
  9. // Configure the interval to select records from 
  10. $interval_start = $today; 
  11. $interval_end = date_i18n( 'Y-m-d 00:00:00', strtotime( "{$today} +{$pmpro_email_days_before_expiration} days", current_time( 'timestamp' ) ) ); 
  12.  
  13. //look for memberships that are going to expire within one week (but we haven't emailed them within a week) 
  14. $sqlQuery = $wpdb->prepare( 
  15. "SELECT DISTINCT 
  16. mu.user_id,  
  17. mu.membership_id,  
  18. mu.startdate,  
  19. mu.enddate,  
  20. um.meta_value AS notice  
  21. FROM {$wpdb->pmpro_memberships_users} AS mu 
  22. LEFT JOIN {$wpdb->usermeta} AS um ON um.user_id = mu.user_id 
  23. AND um.meta_key = %s 
  24. WHERE ( um.meta_value IS NULL OR DATE_ADD(um.meta_value, INTERVAL %d DAY) < %s )  
  25. AND ( mu.status = 'active' )  
  26. AND ( mu.enddate IS NOT NULL ) 
  27. AND ( mu.enddate <> '0000-00-00 00:00:00' ) 
  28. AND ( mu.enddate BETWEEN %s AND %s )  
  29. AND ( mu.membership_id <> 0 OR mu.membership_id <> NULL ) 
  30. ORDERBY mu.enddate 
  31. ",  
  32. "pmpro_expiration_notice",  
  33. $pmpro_email_days_before_expiration,  
  34. $today,  
  35. $interval_start,  
  36. $interval_end 
  37. ); 
  38.  
  39. if(defined('PMPRO_CRON_LIMIT')) 
  40. $sqlQuery .= " LIMIT " . PMPRO_CRON_LIMIT; 
  41.  
  42. $expiring_soon = $wpdb->get_results($sqlQuery); 
  43.  
  44. foreach($expiring_soon as $e) 
  45. $send_email = apply_filters("pmpro_send_expiration_warning_email", true, $e->user_id); 
  46. if($send_email) 
  47. //send an email 
  48. $pmproemail = new PMProEmail(); 
  49. $euser = get_userdata($e->user_id); 
  50. $pmproemail->sendMembershipExpiringEmail($euser); 
  51.  
  52. if(current_user_can('manage_options')) 
  53. printf(__("Membership expiring email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email); 
  54. else 
  55. echo ". "; 
  56.  
  57. //delete all user meta for this key to prevent duplicate user meta rows 
  58. delete_user_meta($e->user_id, "pmpro_expiration_notice"); 
  59.  
  60. //update user meta so we don't email them again 
  61. update_user_meta($e->user_id, "pmpro_expiration_notice", $today);