Skip to content

Instantly share code, notes, and snippets.

@horike37
Last active December 27, 2015 18:49
Show Gist options
  • Save horike37/7372327 to your computer and use it in GitHub Desktop.
Save horike37/7372327 to your computer and use it in GitHub Desktop.
my_cron_schedule_handlerで登録したwp_cronで処理が実行されなかった際に、再実行するコード
<?php
add_action('init', 'my_cron_schedule');
function my_cron_schedule() {
if ( get_option('my_cron_schedule_locked') == 1 )
return;
$crons = _get_cron_array();
foreach ( $crons as $time => $time_cron_array ) {
if ( array_key_exists( 'my_cron_schedule_handler', $time_cron_array ) ) {
if ( time() > $time ) {
// get lock
update_option( 'my_cron_schedule_locked', 1 );
//ここに処理を記述
//delete cron schedule
wp_clear_scheduled_hook( 'my_cron_schedule_handler' );
// lock release
delete_option( 'my_cron_schedule_locked' );
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment