WordPress at a glance

wp_publish_post() WP 1.0

Publish a post by transitioning the post status.

  • Global. wpdb. $wpdb WordPress database abstraction object.
Hooks from function:
Return

Nothing (null).

Usage

wp_publish_post( $post );
$post(int/WP_Post) (required)
Post ID or post object.

Code of wp_publish_post: wp-includes/post.php VER 4.9.8

<?php
function wp_publish_post( $post ) {
	global $wpdb;

	if ( ! $post = get_post( $post ) )
		return;

	if ( 'publish' == $post->post_status )
		return;

	$wpdb->update( $wpdb->posts, array( 'post_status' => 'publish' ), array( 'ID' => $post->ID ) );

	clean_post_cache( $post->ID );

	$old_status = $post->post_status;
	$post->post_status = 'publish';
	wp_transition_post_status( 'publish', $old_status, $post );

	/** This action is documented in wp-includes/post.php */
	do_action( 'edit_post', $post->ID, $post );

	/** This action is documented in wp-includes/post.php */
	do_action( "save_post_{$post->post_type}", $post->ID, $post, true );

	/** This action is documented in wp-includes/post.php */
	do_action( 'save_post', $post->ID, $post, true );

	/** This action is documented in wp-includes/post.php */
	do_action( 'wp_insert_post', $post->ID, $post, true );
}

Related Functions

From category: Insert, delete, update

No comments
    Hello, !     Log In . Register