返回介绍

wp_untrash_post_comments()

发布于 2017-09-11 13:02:17 字数 2837 浏览 944 评论 0 收藏 0

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

Restore comments for a post from the trash.


description


参数

$post

(int|WP_Post|null) (Optional) Post ID or post object. Defaults to global $post.

Default value: null


返回值

(true|void)


源代码

File: wp-includes/post.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 );
}

更新日志

Versiondescription
2.9.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: do_action()
  • wp-includes/post.php: untrash_post_comments
  • wp-includes/post.php: untrashed_post_comments
  • wp-includes/post.php: get_post_meta()
  • wp-includes/post.php: delete_post_meta()
  • wp-includes/post.php: get_post()
  • wp-includes/wp-db.php: wpdb::query()
  • wp-includes/wp-db.php: wpdb::prepare()
  • wp-includes/comment.php: clean_comment_cache()
  • Show 4 more uses Hide more uses

Used By

  • wp-includes/post.php: wp_untrash_post()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文