Last active
December 27, 2015 18:49
-
-
Save horike37/7372327 to your computer and use it in GitHub Desktop.
my_cron_schedule_handlerで登録したwp_cronで処理が実行されなかった際に、再実行するコード
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
<?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