返回介绍

wp_trash_post_comments()

发布于 2017-09-11 13:00:46 字数 2766 浏览 970 评论 0 收藏 0

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

Moves comments for a post to the trash.


description


参数

$post

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

Default value: null


返回值

(mixed|void) False on failure.


源代码

File: wp-includes/post.php

function wp_trash_post_comments( $post = null ) {
	global $wpdb;

	$post = get_post($post);
	if ( empty($post) )
		return;

	$post_id = $post->ID;

	/**
	 * Fires before comments are sent to the trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int $post_id Post ID.
	 */
	do_action( 'trash_post_comments', $post_id );

	$comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_ID, comment_approved FROM $wpdb->comments WHERE comment_post_ID = %d", $post_id) );
	if ( empty($comments) )
		return;

	// Cache current status for each comment.
	$statuses = array();
	foreach ( $comments as $comment )
		$statuses[$comment->comment_ID] = $comment->comment_approved;
	add_post_meta($post_id, '_wp_trash_meta_comments_status', $statuses);

	// Set status for all comments to post-trashed.
	$result = $wpdb->update($wpdb->comments, array('comment_approved' => 'post-trashed'), array('comment_post_ID' => $post_id));

	clean_comment_cache( array_keys($statuses) );

	/**
	 * Fires after comments are sent to the trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int   $post_id  Post ID.
	 * @param array $statuses Array of comment statuses.
	 */
	do_action( 'trashed_post_comments', $post_id, $statuses );

	return $result;
}

更新日志

Versiondescription
2.9.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: do_action()
  • wp-includes/post.php: trash_post_comments
  • wp-includes/post.php: trashed_post_comments
  • wp-includes/post.php: add_post_meta()
  • wp-includes/post.php: get_post()
  • wp-includes/wp-db.php: wpdb::get_results()
  • wp-includes/wp-db.php: wpdb::update()
  • 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_trash_post()

User Contributed Notes

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

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

发布评论

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