Skip to content

Instantly share code, notes, and snippets.

@bigdawggi
Created February 3, 2015 22:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigdawggi/c4edae91da16367735f6 to your computer and use it in GitHub Desktop.
Save bigdawggi/c4edae91da16367735f6 to your computer and use it in GitHub Desktop.
Code to schedule a cron to run at a certain local time
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