wp_publish_post

Publish a post by transitioning the post status.

Description

wp_publish_post( (int|WP_Post) $post ); 

Parameters (1)

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

Usage

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

Defined (1)

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

/wp-includes/post.php  
  1. function wp_publish_post( $post ) { 
  2. global $wpdb; 
  3.  
  4. if ( ! $post = get_post( $post ) ) 
  5. return; 
  6.  
  7. if ( 'publish' == $post->post_status ) 
  8. return; 
  9.  
  10. $wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) ); 
  11.  
  12. clean_post_cache( $post->ID ); 
  13.  
  14. $old_status = $post->post_status; 
  15. $post->post_status = 'publish'; 
  16. wp_transition_post_status( 'publish', $old_status, $post ); 
  17.  
  18. /** This action is documented in wp-includes/post.php */ 
  19. do_action( 'edit_post', $post->ID, $post ); 
  20.  
  21. /** This action is documented in wp-includes/post.php */ 
  22. do_action( "save_post_{$post->post_type}", $post->ID, $post, true ); 
  23.  
  24. /** This action is documented in wp-includes/post.php */ 
  25. do_action( 'save_post', $post->ID, $post, true ); 
  26.  
  27. /** This action is documented in wp-includes/post.php */ 
  28. do_action( 'wp_insert_post', $post->ID, $post, true );