返回介绍

wp_trash_comment()

发布于 2017-09-11 13:00:34 字数 2847 浏览 1054 评论 0 收藏 0

wp_trash_comment( int|WP_Comment $comment_id )

Moves a comment to the Trash


description

If trash is disabled, comment is permanently deleted.


参数

$comment_id

(int|WP_Comment) (Required) Comment ID or WP_Comment object.


返回值

(bool) True on success, false on failure.


源代码

File: wp-includes/comment.php

function wp_trash_comment($comment_id) {
	if ( !EMPTY_TRASH_DAYS )
		return wp_delete_comment($comment_id, true);

	if ( !$comment = get_comment($comment_id) )
		return false;

	/**
	 * Fires immediately before a comment is sent to the Trash.
	 *
	 * @since 2.9.0
	 *
	 * @param int $comment_id The comment ID.
	 */
	do_action( 'trash_comment', $comment->comment_ID );

	if ( wp_set_comment_status( $comment, 'trash' ) ) {
		delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_status' );
		delete_comment_meta( $comment->comment_ID, '_wp_trash_meta_time' );
		add_comment_meta( $comment->comment_ID, '_wp_trash_meta_status', $comment->comment_approved );
		add_comment_meta( $comment->comment_ID, '_wp_trash_meta_time', time() );

		/**
		 * Fires immediately after a comment is sent to Trash.
		 *
		 * @since 2.9.0
		 *
		 * @param int $comment_id The comment ID.
		 */
		do_action( 'trashed_comment', $comment->comment_ID );
		return true;
	}

	return false;
}

更新日志

Versiondescription
2.9.0Introduced.

相关函数

Uses

  • wp-includes/plugin.php: do_action()
  • wp-includes/comment.php: wp_set_comment_status()
  • wp-includes/comment.php: wp_delete_comment()
  • wp-includes/comment.php: trash_comment
  • wp-includes/comment.php: trashed_comment
  • wp-includes/comment.php: delete_comment_meta()
  • wp-includes/comment.php: add_comment_meta()
  • wp-includes/comment.php: get_comment()
  • Show 3 more uses Hide more uses

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::handle_status_param()
  • wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php: WP_REST_Comments_Controller::delete_item()
  • wp-admin/includes/ajax-actions.php: wp_ajax_delete_comment()
  • wp-includes/comment.php: wp_delete_comment()

User Contributed Notes

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

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

发布评论

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