check_and_publish_future_post() WordPress Function

The check_and_publish_future_post() function is used to check if a future post is ready to be published. If the post is ready, it will be published. If the post is not ready, it will remain in the future post queue.

check_and_publish_future_post( int|WP_Post $post_id ) #

Publish 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.


Top ↑

Parameters

$post_id

(int|WP_Post)(Required)Post ID or post object.


Top ↑

Source

File: wp-includes/post.php

function check_and_publish_future_post( $post_id ) {
	$post = get_post( $post_id );

	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 );
}


Top ↑

Changelog

Changelog
VersionDescription
2.5.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More
Show More