钩子文档

pre_reschedule_event

💡 云策文档标注

概述

pre_reschedule_event 是一个 WordPress 过滤器,用于覆盖重复事件的重新调度过程。通过返回非空值,可以短路默认的重调度逻辑,并返回自定义值。

关键要点

  • 过滤器名称:pre_reschedule_event
  • 主要用途:允许插件或主题拦截并自定义重复事件的重新调度行为
  • 短路机制:返回非 null 值(如 true、false 或 WP_Error)将跳过默认重调度,直接返回该值
  • 参数:$pre(默认 null)、$event(事件数据对象)、$wp_error(是否返回 WP_Error)
  • 事件对象属性:包括 hook、timestamp、schedule、args、interval 等
  • 版本变化:WordPress 5.7.0 添加了 $wp_error 参数,支持返回 WP_Error 对象

注意事项

  • 适用于替换 wp-cron 的插件,成功时返回 true,失败时返回 false 或 WP_Error
  • 需谨慎处理返回值,以避免影响事件调度系统的正常运行

📄 原文内容

Filter to override rescheduling of a recurring event.

Description

Returning a non-null value will short-circuit the normal rescheduling process, causing the function to return the filtered value instead.

For plugins replacing wp-cron, return true if the event was successfully rescheduled, false or a WP_Error if not.

Parameters

$prenull|bool|WP_Error
Value to return instead. Default null to continue adding the event.
$eventobject
An object containing an event’s data.

  • hook string
    Action hook to execute when the event is run.
  • timestamp int
    Unix timestamp (UTC) for when to next run the event.
  • schedule string
    How often the event should subsequently recur.
  • args array
    Array containing each separate argument to pass to the hook’s callback function.
  • interval int
    The interval time in seconds for the schedule.

$wp_errorbool
Whether to return a WP_Error on failure.

Source

$pre = apply_filters( 'pre_reschedule_event', null, $event, $wp_error );

Changelog

Version Description
5.7.0 The $wp_error parameter was added, and a WP_Error object can now be returned.
5.1.0 Introduced.