Skip to content

Instantly share code, notes, and snippets.

@codescribblr
Created March 17, 2014 16:25
Show Gist options
  • Select an option

  • Save codescribblr/9602655 to your computer and use it in GitHub Desktop.

Select an option

Save codescribblr/9602655 to your computer and use it in GitHub Desktop.
//Convert start time from local time to GMT since WP Cron sends based on GMT
$start_time_gmt = strtotime( get_gmt_from_date( date( 'Y-m-d H:i:s', $start_time ) ) . ' GMT' );
//Set reminder time for three days before event start time
$time_prior_event = 3 * 24 * 60 * 60; //3 days * 24 hours * 60 minutes * 60 seconds
$reminder_time = $start_time_gmt - $time_prior_event;
//Remove existing cron event for this post if one exists
//We pass $post_id because cron event arguments are required to remove the scheduled event
wp_clear_scheduled_hook( 'wi_send_reminder_email', array( $post_id ) );
//Schedule the reminder
wp_schedule_single_event( $reminder_time, 'wi_send_reminder_email', array( $post_id ) );
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment