Created
March 17, 2014 16:25
-
-
Save codescribblr/9602655 to your computer and use it in GitHub Desktop.
Add single use cron job in Wordpress
From http://wp.smashingmagazine.com/2013/10/16/schedule-events-using-wordpress-cron/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //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