Created
February 3, 2015 22:30
-
-
Save bigdawggi/c4edae91da16367735f6 to your computer and use it in GitHub Desktop.
Code to schedule a cron to run at a certain local time
This file contains 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
add_action( 'init', function() { | |
/* must have this check here, b/c although a new cron event won't be added without it, | |
*the wp_schedule_event() function triggers the action to run immediately, even if | |
*set for a different time of day. */ | |
if ( ! wp_next_scheduled( 'social_delete_posts' ) ) { | |
$local_time_to_run = '1am'; | |
$timestamp = strtotime( $local_time_to_run ) + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ); | |
wp_schedule_event( | |
$timestamp, | |
'daily', | |
'social_delete_posts' | |
); | |
} | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment