wp_trash_comment() - WordPress 函数参考中文文档

返回介绍

wp_trash_comment()

发布于 2017-09-11 字数 2849 浏览 951 评论 0

wp_trash_comment( int|WP_Comment $comment_id )

Moves a comment to the Trash


描述

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;
}

更新日志

Version 描述
2.9.0 Introduced.

相关函数

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!