/** * Callback for daily edd events to * * @return bool */ function edd_drip_daily_scheduled_events_func() { //Make sure EDD - licensing is installed and these functions/hooks still exist if (!function_exists('edd_sl_get_renewal_notice_periods') || !function_exists('edd_sl_get_expiring_licenses') || !has_action('edd_sl_send_scheduled_reminder_for_license')) { error_log('edd-drip warning:EDD function is no longer available.'); return false; } //Fire an event for all edd renewal periods - will fire ONCE for each customer/license foreach (edd_sl_get_renewal_notice_periods() as $period => $label) { //This corrects a bug in EDD where the period = 'expired' //When the edd_sl_get_expiring_licenses is called it will not use the correct date range //to find expired licenses and suspect ALL expired licenses will be returned if ('expired' == $period) { $period = 'today'; } //Get the expiring licenses for this period $expiring_license_ids = edd_sl_get_expiring_licenses($period); //No expiring licenses for this period if (false === $expiring_license_ids) { continue; } //Expiring license keys found - fire drip events foreach ($expiring_license_ids as $license_id) { //make sure download is published - notice_id is not used in function so default to 0 if (!apply_filters('edd_sl_send_scheduled_reminder_for_license', true, $license_id, 0)) { continue; } //Was the renewal event already fired for this license + period? $sent_time = get_post_meta($license_id, sanitize_key('_edd_sl_drip_renewal_sent_' . $period), true); //error_log(var_export(sanitize_key( '_edd_sl_drip_renewal_sent_' . $period ),true)); if ($sent_time) { $expire_date = strtotime($period, $sent_time); if (time() < $expire_date) { // The renewal period isn't expired yet so don't send again continue; } delete_post_meta($license_id, sanitize_key('_edd_sl_drip_renewal_sent_' . $period)); } //fire drip event $this->fire_drip_expired_event($license_id, $period); } } }
function edd_sl_scheduled_reminders() { global $edd_options; if (!isset($edd_options['edd_sl_send_renewal_reminders'])) { return; } $edd_sl_emails = new EDD_SL_Emails(); $notices = edd_sl_get_renewal_notices(); foreach ($notices as $notice_id => $notice) { if ('expired' == $notice['send_period']) { continue; // Expired notices are triggered from the set_license_status() method of EDD_Software_Licensing } $keys = edd_sl_get_expiring_licenses($notice['send_period']); if (!$keys) { continue; } foreach ($keys as $license_id) { if (!apply_filters('edd_sl_send_scheduled_reminder_for_license', true, $license_id, $notice_id)) { continue; } $sent_time = get_post_meta($license_id, sanitize_key('_edd_sl_renewal_sent_' . $notice['send_period']), true); if ($sent_time) { $expire_date = strtotime($notice['send_period'], $sent_time); if (time() < $expire_date) { // The renewal period isn't expired yet so don't send again continue; } delete_post_meta($license_id, sanitize_key('_edd_sl_renewal_sent_' . $notice['send_period'])); } $edd_sl_emails->send_renewal_reminder($license_id, $notice_id); } } }