wp_publish_post

Definition:
function wp_publish_post($post_id) {}

Publish a post by transitioning the post status.

Parameters

  • int $post_id: Post ID.

Defined actions

  • edit_post
    do_action('edit_post', $post_id, $post);
  • save_post
    do_action('save_post', $post_id, $post);
  • wp_insert_post
    do_action('wp_insert_post', $post_id, $post);

Source code

function wp_publish_post($post_id) {

	global $wpdb;



	$post = get_post($post_id);



	if ( empty($post) )

		return;



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

		return;



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



	$old_status = $post->post_status;

	$post->post_status = 'publish';

	wp_transition_post_status('publish', $old_status, $post);



	do_action('edit_post', $post_id, $post);

	do_action('save_post', $post_id, $post);

	do_action('wp_insert_post', $post_id, $post);

}

4009

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:

WordPress.com Logo

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

Facebook photo

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

Connecting to %s

%d bloggers like this: