pmpro_cron_trial_ending_warnings

The Paid Memberships Pro pmpro cron trial ending warnings function.

Description

pmpro_cron_trial_ending_warnings(); 

Usage

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

Defined (1)

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

/scheduled/crons.php  
  1. function pmpro_cron_trial_ending_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_trial_end = apply_filters("pmpro_email_days_before_trial_end", 7); 
  8.  
  9. //look for memberships with trials ending soon (but we haven't emailed them within a week) 
  10. $sqlQuery = " 
  11. SELECT 
  12. mu.user_id, mu.membership_id, mu.startdate, mu.cycle_period, mu.trial_limit FROM $wpdb->pmpro_memberships_users mu LEFT JOIN $wpdb->usermeta um ON um.user_id = mu.user_id AND um.meta_key = 'pmpro_trial_ending_notice' 
  13. WHERE 
  14. mu.status = 'active' AND mu.trial_limit IS NOT NULL AND mu.trial_limit > 0 AND 
  15. (cycle_period = 'Day' AND DATE_ADD(mu.startdate, INTERVAL mu.trial_limit Day) <= DATE_ADD('" . $today . "', INTERVAL " . $pmpro_email_days_before_trial_end . " Day)) OR 
  16. (cycle_period = 'Week' AND DATE_ADD(mu.startdate, INTERVAL mu.trial_limit Week) <= DATE_ADD('" . $today . "', INTERVAL " . $pmpro_email_days_before_trial_end . " Day)) OR 
  17. (cycle_period = 'Month' AND DATE_ADD(mu.startdate, INTERVAL mu.trial_limit Month) <= DATE_ADD('" . $today . "', INTERVAL " . $pmpro_email_days_before_trial_end . " Day)) OR 
  18. (cycle_period = 'Year' AND DATE_ADD(mu.startdate, INTERVAL mu.trial_limit Year) <= DATE_ADD('" . $today . "', INTERVAL " . $pmpro_email_days_before_trial_end . " Day)) 
  19.  
  20. AND (um.meta_value IS NULL OR um.meta_value = '' OR DATE_ADD(um.meta_value, INTERVAL " . $pmpro_email_days_before_trial_end . " Day) <= '" . $today . "') 
  21. ORDERBY mu.startdate"; 
  22.  
  23. $trial_ending_soon = $wpdb->get_results($sqlQuery); 
  24.  
  25. foreach($trial_ending_soon as $e) 
  26. $send_email = apply_filters("pmpro_send_trial_ending_email", true, $e->user_id); 
  27. if($send_email) 
  28. //send an email 
  29. $pmproemail = new PMProEmail(); 
  30. $euser = get_userdata($e->user_id); 
  31. $pmproemail->sendTrialEndingEmail($euser); 
  32.  
  33. if(current_user_can('manage_options')) 
  34. printf(__("Trial ending email sent to %s. ", 'paid-memberships-pro' ), $euser->user_email); 
  35. else 
  36. echo ". "; 
  37.  
  38. //update user meta so we don't email them again 
  39. update_user_meta($e->user_id, "pmpro_trial_ending_notice", $today);