
2020年最新版本WordPress本地环境搭建与安装教程
check_and_publish_future_post ( $post )
check_and_publish_future_post: 这个函数检查一个预定的文章是否应该被发布,如果是,就发布它。它被WordPress内部用来发布预定的文章。
发布未来的文章,并确保文章ID具有未来的文章状态。
由cron’publish_future_post’事件调用。这一保障措施可以防止cron发布草稿等。
function check_and_publish_future_post( $post ) { $post = get_post( $post ); if ( ! $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 ); }