发布以后的帖子并确保帖子ID具有未来的帖子状态。
原型
check_and_publish_future_post( int|WP_Post $post_id )
描述
由cron’buate_future_post’事件调用。这种安全措施可以防止cron发布草稿等。
参数
$post_id
(int|WP_Post)
(Required)
帖子ID或帖子对象。
源文件
路径:wp-includes/post.php
<?php
...
function check_and_publish_future_post( $post_id ) {
$post = get_post($post_id);
if ( empty($post) )
return;
if ( 'future' != $post->post_status )
return;
$time = strtotime( $post->post_date_gmt . ' GMT' );
// Uh oh, someone jumped the gun!
if ( $time > time() ) {
wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system
wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) );
return;
}
// wp_publish_post() returns no meaningful value.
wp_publish_post( $post_id );
}
...
?>
其他
英文文档:https://developer.wordpress.org/reference/functions/check_and_publish_future_post/