# wp_set_comment_status()

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

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

## Сигнатура

```php
wp_set_comment_status( int|WP_Comment $comment_id, string $comment_status, bool $wp_error = false ): bool|WP_Error
```

## Описание

Действие 'wp_set_comment_status' вызывается после обработки комментария.
Если статус комментария отсутствует в списке, возвращается false.

## Параметры

- `$comment_id` `int|WP_Comment` — обязательный. Идентификатор комментария или объект WP_Comment.
- `$comment_status` `string` — обязательный. Новый статус комментария: 'hold', 'approve', 'spam' или 'trash'.
- `$wp_error` `bool` — необязательный, по умолчанию `false`. Возвращать ли объект WP_Error в случае сбоя.

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

`bool|WP_Error` — WP_Error

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

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

```php
function wp_set_comment_status( $comment_id, $comment_status, $wp_error = false ) {
	global $wpdb;

	switch ( $comment_status ) {
		case 'hold':
		case '0':
			$status = '0';
			break;
		case 'approve':
		case '1':
			$status = '1';
			add_action( 'wp_set_comment_status', 'wp_new_comment_notify_postauthor' );
			break;
		case 'spam':
			$status = 'spam';
			break;
		case 'trash':
			$status = 'trash';
			break;
		default:
			return false;
	}

	$comment_old = clone get_comment( $comment_id );

	if ( ! $wpdb->update( $wpdb->comments, array( 'comment_approved' => $status ), array( 'comment_ID' => $comment_old->comment_ID ) ) ) {
		if ( $wp_error ) {
			return new WP_Error( 'db_update_error', __( 'Could not update comment status.' ), $wpdb->last_error );
		} else {
			return false;
		}
	}

	clean_comment_cache( $comment_old->comment_ID );

	$comment = get_comment( $comment_old->comment_ID );

	/**
	 * Fires immediately after transitioning a comment's status from one to another in the database
	 * and removing the comment from the object cache, but prior to all status transition hooks.
	 *
	 * @since 1.5.0
	 *
	 * @param string $comment_id     Comment ID as a numeric string.
	 * @param string $comment_status Current comment status. Possible values include
	 *                               'hold', '0', 'approve', '1', 'spam', and 'trash'.
	 */
	do_action( 'wp_set_comment_status', $comment->comment_ID, $comment_status );

	wp_transition_comment_status( $comment_status, $comment_old->comment_approved, $comment );

	wp_update_comment_count( $comment->comment_post_ID );

	return true;
}
```

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

- 1.0.0 — Introduced.

## Связанные

Использует: `wpdb::update`, [`clean_comment_cache`](https://chugunov.pro/api-wordpress/functions/clean_comment_cache/), [`wp_update_comment_count`](https://chugunov.pro/api-wordpress/functions/wp_update_comment_count/), [`wp_transition_comment_status`](https://chugunov.pro/api-wordpress/functions/wp_transition_comment_status/), [`__`](https://chugunov.pro/api-wordpress/functions/__/), [`add_action`](https://chugunov.pro/api-wordpress/functions/add_action/), [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/), [`get_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/), `WP_Error::__construct`.
Используется в: `WP_REST_Comments_Controller::handle_status_param`, [`wp_ajax_dim_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_dim_comment/), [`wp_ajax_replyto_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_replyto_comment/), [`wp_spam_comment`](https://chugunov.pro/api-wordpress/functions/wp_spam_comment/), [`wp_unspam_comment`](https://chugunov.pro/api-wordpress/functions/wp_unspam_comment/), [`wp_trash_comment`](https://chugunov.pro/api-wordpress/functions/wp_trash_comment/), [`wp_untrash_comment`](https://chugunov.pro/api-wordpress/functions/wp_untrash_comment/).

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