function check_and_publish_future_post($post_id) {}

Publish future post and make sure post ID has future post status.
Invoked by cron ‘publish_future_post’ event. This safeguard prevents cron from publishing drafts, etc.


  • int $post_id: Post ID.

Return values

returns:Nothing is returned. Which can mean that no action is required or post was published.

Source code

function check_and_publish_future_post($post_id) {

	$post = get_post($post_id);

	if ( empty($post) )


	if ( 'future' != $post->post_status )


	$time = strtotime( $post->post_date_gmt . ' GMT' );

	if ( $time > time() ) { // Uh oh, someone jumped the gun!

		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($post_id);



No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: