_transition_post_status

Hook for managing future post transitions to published.

Description

_transition_post_status( (string) $new_status, (string) $old_status, (WP_Post) $post ); 

Parameters (3)

0. $new_status (string)
New post status.
1. $old_status (string)
Previous post status.
2. $post (WP_Post)
Post object.

Usage

  1. if ( !function_exists( '_transition_post_status' ) ) { 
  2. require_once ABSPATH . WPINC . '/post.php'; 
  3.  
  4. // New post status. 
  5. $new_status = ''; 
  6.  
  7. // Previous post status. 
  8. $old_status = ''; 
  9.  
  10. // Post object. 
  11. $post = null; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = _transition_post_status($new_status, $old_status, $post); 
  15.  

Defined (1)

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

/wp-includes/post.php  
  1. function _transition_post_status( $new_status, $old_status, $post ) { 
  2. global $wpdb; 
  3.  
  4. if ( $old_status != 'publish' && $new_status == 'publish' ) { 
  5. // Reset GUID if transitioning to publish and it is empty. 
  6. if ( '' == get_the_guid($post->ID) ) 
  7. $wpdb->update( $wpdb->posts, array( 'guid' => get_permalink( $post->ID ) ), array( 'ID' => $post->ID ) ); 
  8.  
  9. /** 
  10. * Fires when a post's status is transitioned from private to published. 
  11. * @since 1.5.0 
  12. * @deprecated 2.3.0 Use 'private_to_publish' instead. 
  13. * @param int $post_id Post ID. 
  14. */ 
  15.  
  16. // If published posts changed clear the lastpostmodified cache. 
  17. if ( 'publish' == $new_status || 'publish' == $old_status) { 
  18. foreach ( array( 'server', 'gmt', 'blog' ) as $timezone ) { 
  19. wp_cache_delete( "lastpostmodified:$timezone", 'timeinfo' ); 
  20. wp_cache_delete( "lastpostdate:$timezone", 'timeinfo' ); 
  21. wp_cache_delete( "lastpostdate:$timezone:{$post->post_type}", 'timeinfo' ); 
  22.  
  23. if ( $new_status !== $old_status ) { 
  24. wp_cache_delete( _count_posts_cache_key( $post->post_type ), 'counts' ); 
  25. wp_cache_delete( _count_posts_cache_key( $post->post_type, 'readable' ), 'counts' ); 
  26.  
  27. // Always clears the hook in case the post status bounced from future to draft. 
  28. wp_clear_scheduled_hook('publish_future_post', array( $post->ID ) );