_future_post_hook()
云策文档标注
概述
_future_post_hook() 是一个 WordPress Hook,用于调度标记为未来发布的文章的发布。它通过清除和重新安排单次事件来实现定时发布功能。
关键要点
- 该 Hook 主要用于处理未来文章的发布调度,确保文章在指定时间自动发布。
- 参数 $deprecated 未使用,可设为 null,但未标记为弃用以避免与 wp_transition_post_status() 冲突。
- 必须的 $post 参数是一个 WP_Post 对象,需要包含 'ID' 和 'post_date_gmt' 属性。
- 内部使用 wp_clear_scheduled_hook() 和 wp_schedule_single_event() 来管理定时任务。
代码示例
function _future_post_hook( $deprecated, $post ) {
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) );
}注意事项
- 此 Hook 自 WordPress 2.3.0 版本引入,是核心调度机制的一部分。
- 开发者应确保 $post 对象正确传递,避免因缺少必要属性导致调度失败。
原文内容
Hook used to schedule publication for a post marked for the future.
Description
The $post properties used and must exist are ‘ID’ and ‘post_date_gmt’.
Parameters
$deprecatedintrequired-
Not used. Can be set to null. Never implemented. Not marked as deprecated with _deprecated_argument() as it conflicts with wp_transition_post_status() and the default filter for _future_post_hook() .
More Arguments from _future_post_hook( … $deprecated )
Not used. Can be set to null. Never implemented. Not marked as deprecated with _deprecated_argument() as it conflicts with wp_transition_post_status() and the default filter for _future_post_hook() .
$postWP_Postrequired-
Post object.
Source
function _future_post_hook( $deprecated, $post ) {
wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
wp_schedule_single_event( strtotime( get_gmt_from_date( $post->post_date ) . ' GMT' ), 'publish_future_post', array( $post->ID ) );
}
Changelog
| Version | Description |
|---|---|
| 2.3.0 | Introduced. |