通过转换帖子状态发布帖子。

原型

wp_publish_post( int|WP_Post $post )

参数

$post (int|WP_Post) (Required) 帖子ID或帖子对象。

源文件

路径:wp-includes/post.php

<?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 );
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_publish_post/