wp_publish_post()

You are here:

wp_publish_post( int|WP_Post $post )

Publish a post by transitioning the post status.

Parameters Parameters

$post

(int|WP_Post) (Required) Post ID or post object.


Top ↑

More Information More Information

This function does not do anything except transition the post status. If you want to ensure post_name is set, use wp_update_post() instead.


Top ↑

Source Source

File: wp-includes/post.php

4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
function wp_publish_post( $post ) {
    global $wpdb;
 
    $post = get_post( $post );
    if ( ! $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->post_type}", $post->ID, $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 );
}


Top ↑

Changelog Changelog

Changelog
Version Description
2.1.0 Introduced.
Was this article helpful?
Dislike 0
Views: 12