예제 #1
0
function pmpro_cron_trial_ending_warnings()
{
    global $wpdb;
    //make sure we only run once a day
    $today = date("Y-m-d 00:00:00");
    $pmpro_email_days_before_trial_end = apply_filters("pmpro_email_days_before_trial_end", 7);
    //look for memberships with trials ending soon (but we haven't emailed them within a week)
    $sqlQuery = "\n\t\tSELECT \n\t\t\tmu.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' \n\t\tWHERE \n\t\t\tmu.status = 'active' AND mu.trial_limit IS NOT NULL AND mu.trial_limit > 0 AND\n\t\t\t(\n\t\t\t\t(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\n\t\t\t\t(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\n\t\t\t\t(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\n\t\t\t\t(cycle_period = 'Year' AND DATE_ADD(mu.startdate, INTERVAL mu.trial_limit Year) <= DATE_ADD('" . $today . "', INTERVAL " . $pmpro_email_days_before_trial_end . " Day)) \n\t\t\t)\t\t\n\t\t\t\t\t\t\n\t\t\tAND (um.meta_value IS NULL OR um.meta_value = '' OR DATE_ADD(um.meta_value, INTERVAL " . $pmpro_email_days_before_trial_end . " Day) <= '" . $today . "') \n\t\tORDER BY mu.startdate";
    $trial_ending_soon = $wpdb->get_results($sqlQuery);
    foreach ($trial_ending_soon as $e) {
        $send_email = apply_filters("pmpro_send_trial_ending_email", true, $e->user_id);
        if ($send_email) {
            //send an email
            $pmproemail = new PMProEmail();
            $euser = get_userdata($e->user_id);
            $pmproemail->sendTrialEndingEmail($euser);
            printf(__("Trial ending email sent to %s. ", "pmpro"), $euser->user_email);
        }
        //update user meta so we don't email them again
        update_user_meta($euser->ID, "pmpro_trial_ending_notice", $today);
    }
}