# wp_trash_comment()

URL: https://chugunov.pro/api-wordpress/functions/wp_trash_comment/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.9.0.

## Сигнатура

```php
wp_trash_comment( int|WP_Comment $comment_id ): bool
```

## Описание

Если корзина отключена, комментарий удаляется безвозвратно.

## Параметры

- `$comment_id` `int|WP_Comment` — обязательный. Идентификатор комментария или объект WP_Comment.

## Возвращаемое значение

`bool`

## Исходный код

Файл: `wp-includes/comment.php:1585`

```php
function wp_trash_comment( $comment_id ) {
	if ( ! EMPTY_TRASH_DAYS ) {
		$comment = get_comment( $comment_id );
		$success = wp_delete_comment( $comment_id, true );

		if ( ! $success ) {
			return false;
		}

		// Also delete children of top level 'note' type comments.
		if ( $comment && 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
			$children = $comment->get_children(
				array(
					'fields' => 'ids',
					'status' => 'all',
					'type'   => 'note',
				)
			);

			foreach ( $children as $child_id ) {
				if ( ! wp_delete_comment( $child_id, true ) ) {
					$success = false;
				}
			}
		}

		return $success;
	}

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

	/**
	 * Fires immediately before a comment is sent to the Trash.
	 *
	 * @since 2.9.0
	 * @since 4.9.0 Added the `$comment` parameter.
	 *
	 * @param string     $comment_id The comment ID as a numeric string.
	 * @param WP_Comment $comment    The comment to be trashed.
	 */
	do_action( 'trash_comment', $comment->comment_ID, $comment );

	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
		 * @since 4.9.0 Added the `$comment` parameter.
		 *
		 * @param string     $comment_id The comment ID as a numeric string.
		 * @param WP_Comment $comment    The trashed comment.
		 */
		do_action( 'trashed_comment', $comment->comment_ID, $comment );

		// For top level 'note' type comments, also trash children.
		if ( 'note' === $comment->comment_type && 0 === (int) $comment->comment_parent ) {
			$children = $comment->get_children(
				array(
					'fields' => 'ids',
					'status' => 'all',
					'type'   => 'note',
				)
			);

			$success = true;
			foreach ( $children as $child_id ) {
				if ( ! wp_trash_comment( $child_id ) ) {
					$success = false;
				}
			}
			return $success;
		}

		return true;
	}

	return false;
}
```

## История изменений

- 6.9.0 — Any child notes are deleted when deleting a note.
- 2.9.0 — Introduced.

## Связанные

Использует: [`wp_set_comment_status`](https://chugunov.pro/api-wordpress/functions/wp_set_comment_status/), [`wp_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_delete_comment/), [`wp_trash_comment`](https://chugunov.pro/api-wordpress/functions/wp_trash_comment/), [`delete_comment_meta`](https://chugunov.pro/api-wordpress/functions/delete_comment_meta/), [`add_comment_meta`](https://chugunov.pro/api-wordpress/functions/add_comment_meta/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/), [`get_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/).
Используется в: `WP_REST_Comments_Controller::handle_status_param`, `WP_REST_Comments_Controller::delete_item`, [`wp_ajax_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_delete_comment/), [`wp_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_delete_comment/), [`wp_trash_comment`](https://chugunov.pro/api-wordpress/functions/wp_trash_comment/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/wp_trash_comment/
