質問

I' like to run a cron every 24 hours at midnight PST ( = GMT -8 )

This is what I have

if ( !wp_next_scheduled( 'cron_hook' ) ) {
    //reset on 00:00 PST ( GMT -8 ) == GMT +16
    $timeoffset = strtotime('midnight')+((24-8)*HOUR_IN_SECONDS);
    if($timeoffset < time()) $timeoffset+(24*HOUR_IN_SECONDS);
    wp_schedule_event($timeoffset, 'daily', 'cron_hook');
}

This sets a daily cron on midnight GMT -8 (24-8) and postpone it 24 hours if it's already in the past so the cron doesn't get triggered at the time of creating.

Am I correct with this approach or do I miss something?

I've already tested it but since my server is running with GMT + 0 I cant verify that for other timezone

正しい解決策はありません

ライセンス: CC-BY-SA帰属
所属していません wordpress.stackexchange
scroll top