我目前正在开发一个使用WP cron的插件。在安装插件的过程中,我创建了两个需要的cron作业,时间戳为午夜-2,a和午夜-1小时,因为作业2只在工作1之后运行1小时。
即使在创建过程中使用时间戳(未来的时间为3-4小时),这两个函数似乎都是在插件安装/更新之后直接执行的,这导致了许多问题。
wp_schedule_event( strtotime( 'midnight' ) + ( - 2 * HOUR_IN_SECONDS ), 'daily', 'test1' );
wp_schedule_event( strtotime( 'midnight' ) + ( - 1 * HOUR_IN_SECONDS ), 'daily', 'test2' );知道如何在创建过程中防止每个事件的初始执行吗?
发布于 2022-07-19 21:45:54
strtotime( 'midnight' )会给你今天的午夜时间,这已经发生了!你明天想要午夜。
7月19日的date( 'F jS H:i:s', strtotime( 'midnight' ) )是July 19th 00:00:00
然而,date( 'F jS H:i:s', strtotime( 'tomorrow midnight' ) )将是July 20th 00:00:00
...which是你想要的!所以,只需使用tomorrow midnight。
https://wordpress.stackexchange.com/questions/407825
复制相似问题