On this page
check_and_publish_future_post( int|WP_Post $post )
Publishes future post and make sure post ID has future post status.
Description
Invoked by cron ‘publish_future_post’ event. This safeguard prevents cron from publishing drafts, etc.
Parameters
$postint|WP_Post Required-
Post ID or post object.
Source
File: wp-includes/post.php. View all references
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 );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_clear_scheduled_hook() wp-includes/cron.php | Unschedules all events attached to the hook with the specified arguments. |
| wp_schedule_single_event() wp-includes/cron.php | Schedules an event to run only once. |
| wp_publish_post() wp-includes/post.php | Publishes a post by transitioning the post status. |
| get_post() wp-includes/post.php | Retrieves post data given a post ID or post object. |
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/check_and_publish_future_post