check_and_publish_future_post

Publish future post and make sure post ID has future post status.

Description

check_and_publish_future_post( (int|WP_Post) $post_id ); 

Invoked by cron publish_future_post event. This safeguard prevents cron from publishing drafts, etc.

Parameters (1)

0. $post_id (int|WP_Post)
Post ID or post object.

Usage

  1. if ( !function_exists( 'check_and_publish_future_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // Post ID or post object. 
  5. $post_id = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = check_and_publish_future_post($post_id); 
  9.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/post.php  
  1. function check_and_publish_future_post( $post_id ) { 
  2. $post = get_post($post_id); 
  3.  
  4. if ( empty($post) ) 
  5. return; 
  6.  
  7. if ( 'future' != $post->post_status ) 
  8. return; 
  9.  
  10. $time = strtotime( $post->post_date_gmt . ' GMT' ); 
  11.  
  12. // Uh oh, someone jumped the gun! 
  13. if ( $time > time() ) { 
  14. wp_clear_scheduled_hook( 'publish_future_post', array( $post_id ) ); // clear anything else in the system 
  15. wp_schedule_single_event( $time, 'publish_future_post', array( $post_id ) ); 
  16. return; 
  17.  
  18. // wp_publish_post() returns no meaningful value. 
  19. wp_publish_post( $post_id );