wp_publish_post()通过id修改文章成发布状态

目录

描述

译文

通过更改文章状态来发表文章。

原文

Publish a post by transitioning the post status.

Note: 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.

wp_publish_post() 描述

用法

<?php wp_publish_post$post_id ?>

wp_publish_post() 用法

参数

$post_id

(integer) (必填) Post ID.

默认值: None

wp_publish_post() 参数

返回值

(null) 

wp_publish_post() 返回值

注意

wp_publish_post() 注意

历史

添加于 版本: 2.1.0

wp_publish_post() 历史

源文件

wp_publish_post() 函数的代码位于 wp-includes/post.php.

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Publish a post by transitioning the post status.
 *
 * @since 2.1.0
 *
 * @global wpdb $wpdb WordPress database abstraction object.
 *
 * @param int|WP_Post $post Post ID or post object.
 */
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 );
}

wp_publish_post() 源文件

相关