# wp_transition_comment_status()

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

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

## Сигнатура

```php
wp_transition_comment_status( string $new_status, string $old_status, WP_Comment $comment )
```

## Описание

Вызывает хуки для переходов статуса комментария. Если новый статус комментария отличается от предыдущего, будут запущены два хука; первый — 'transition_comment_status' с новым статусом, старым статусом и данными комментария.
Следующим вызывается действие 'comment_$old_status_to_$new_status'. Оно получает данные комментария.
Последнее действие выполняется независимо от того, совпадают статусы комментария или нет.
Это действие называется 'comment_$new_status_$comment->comment_type'.

## Параметры

- `$new_status` `string` — обязательный. Новый статус комментария.
- `$old_status` `string` — обязательный. Предыдущий статус комментария.
- `$comment` `WP_Comment` — обязательный. Объект комментария.

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

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

```php
function wp_transition_comment_status( $new_status, $old_status, $comment ) {
	/*
	 * Translate raw statuses to human-readable formats for the hooks.
	 * This is not a complete list of comment status, it's only the ones
	 * that need to be renamed.
	 */
	$comment_statuses = array(
		0         => 'unapproved',
		'hold'    => 'unapproved', // wp_set_comment_status() uses "hold".
		1         => 'approved',
		'approve' => 'approved',   // wp_set_comment_status() uses "approve".
	);
	if ( isset( $comment_statuses[ $new_status ] ) ) {
		$new_status = $comment_statuses[ $new_status ];
	}
	if ( isset( $comment_statuses[ $old_status ] ) ) {
		$old_status = $comment_statuses[ $old_status ];
	}

	// Call the hooks.
	if ( $new_status !== $old_status ) {
		/**
		 * Fires when the comment status is in transition.
		 *
		 * @since 2.7.0
		 *
		 * @param string     $new_status The new comment status.
		 * @param string     $old_status The old comment status.
		 * @param WP_Comment $comment    Comment object.
		 */
		do_action( 'transition_comment_status', $new_status, $old_status, $comment );

		/**
		 * Fires when the comment status is in transition from one specific status to another.
		 *
		 * The dynamic portions of the hook name, `$old_status`, and `$new_status`,
		 * refer to the old and new comment statuses, respectively.
		 *
		 * Possible hook names include:
		 *
		 *  - `comment_unapproved_to_approved`
		 *  - `comment_spam_to_approved`
		 *  - `comment_approved_to_unapproved`
		 *  - `comment_spam_to_unapproved`
		 *  - `comment_unapproved_to_spam`
		 *  - `comment_approved_to_spam`
		 *
		 * @since 2.7.0
		 *
		 * @param WP_Comment $comment Comment object.
		 */
		do_action( "comment_{$old_status}_to_{$new_status}", $comment );
	}
	/**
	 * Fires when the status of a specific comment type is in transition.
	 *
	 * The dynamic portions of the hook name, `$new_status`, and `$comment->comment_type`,
	 * refer to the new comment status, and the type of comment, respectively.
	 *
	 * Typical comment types include 'comment', 'pingback', or 'trackback'.
	 *
	 * Possible hook names include:
	 *
	 *  - `comment_approved_comment`
	 *  - `comment_approved_pingback`
	 *  - `comment_approved_trackback`
	 *  - `comment_unapproved_comment`
	 *  - `comment_unapproved_pingback`
	 *  - `comment_unapproved_trackback`
	 *  - `comment_spam_comment`
	 *  - `comment_spam_pingback`
	 *  - `comment_spam_trackback`
	 *
	 * @since 2.7.0
	 *
	 * @param string     $comment_id The comment ID as a numeric string.
	 * @param WP_Comment $comment    Comment object.
	 */
	do_action( "comment_{$new_status}_{$comment->comment_type}", $comment->comment_ID, $comment );
}
```

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

- 2.7.0 — Introduced.

## Связанные

Использует: [`do_action`](https://chugunov.pro/api-wordpress/functions/do_action/).
Используется в: [`wp_set_comment_status`](https://chugunov.pro/api-wordpress/functions/wp_set_comment_status/), [`wp_update_comment`](https://chugunov.pro/api-wordpress/functions/wp_update_comment/), [`wp_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_delete_comment/).

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