从回收站恢复帖子的评论。

原型

wp_untrash_post_comments( int|WP_Post|null $post = null )

参数

$post (int|WP_Post|null) (Optional)  帖子ID或帖子对象。默认为全球$ post。

返回值

(true|void)  

源文件

路径:wp-includes/post.php

<?php
...
function wp_untrash_post_comments( $post = null ) {
	global $wpdb;
	$post = get_post($post);
	if ( empty($post) )
		return;
	$post_id = $post->ID;
	$statuses = get_post_meta($post_id, '_wp_trash_meta_comments_status', true);
	if ( empty($statuses) )
		return true;
	/**
	 * Fires before comments are restored for a post from the trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int $post_id Post ID.
	 */
	do_action( 'untrash_post_comments', $post_id );
	// Restore each comment to its original status.
	$group_by_status = array();
	foreach ( $statuses as $comment_id => $comment_status )
		$group_by_status[$comment_status][] = $comment_id;
	foreach ( $group_by_status as $status => $comments ) {
		// Sanity check. This shouldn't happen.
		if ( 'post-trashed' == $status ) {
			$status = '0';
		}
		$comments_in = implode( ', ', array_map( 'intval', $comments ) );
		$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->comments SET comment_approved = %s WHERE comment_ID IN ($comments_in)", $status ) );
	}
	clean_comment_cache( array_keys($statuses) );
	delete_post_meta($post_id, '_wp_trash_meta_comments_status');
	/**
	 * Fires after comments are restored for a post from the trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int $post_id Post ID.
	 */
	do_action( 'untrashed_post_comments', $post_id );
}
...
?>

其他

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