# get_comment()

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

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

## Сигнатура

```php
get_comment( WP_Comment|string|int $comment = null, string $output = OBJECT ): WP_Comment|array|null
```

## Описание

Если передан объект, данные комментария кэшируются и возвращаются после прохождения через фильтр. Если комментарий пуст, используется глобальная переменная комментария, если она задана.

## Параметры

- `$comment` `WP_Comment|string|int` — необязательный, по умолчанию `null`. Комментарий для получения.
- `$output` `string` — необязательный, по умолчанию `OBJECT`. Требуемый тип возвращаемого значения. Одно из OBJECT, ARRAY_A или ARRAY_N, что соответствует объекту WP_Comment, ассоциативному массиву или числовому массиву соответственно.

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

`WP_Comment|array|null`

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

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

```php
function get_comment( $comment = null, $output = OBJECT ) {
	if ( empty( $comment ) && isset( $GLOBALS['comment'] ) ) {
		$comment = $GLOBALS['comment'];
	}

	if ( $comment instanceof WP_Comment ) {
		$_comment = $comment;
	} elseif ( is_object( $comment ) ) {
		$_comment = new WP_Comment( $comment );
	} else {
		$_comment = WP_Comment::get_instance( $comment );
	}

	if ( ! $_comment ) {
		return null;
	}

	/**
	 * Fires after a comment is retrieved.
	 *
	 * @since 2.3.0
	 *
	 * @param WP_Comment|null $_comment Comment data.
	 */
	$_comment = apply_filters( 'get_comment', $_comment );
	if ( ! ( $_comment instanceof WP_Comment ) ) {
		return null;
	}

	if ( OBJECT === $output ) {
		return $_comment;
	} elseif ( ARRAY_A === $output ) {
		return $_comment->to_array();
	} elseif ( ARRAY_N === $output ) {
		return array_values( $_comment->to_array() );
	}
	return $_comment;
}
```

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

- 2.0.0 — Introduced.

## Связанные

Использует: `WP_Comment::__construct`, `WP_Comment::get_instance`, `WP_Comment`, [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/).
Используется в: [`_get_comment_reply_id`](https://chugunov.pro/api-wordpress/functions/_get_comment_reply_id/), [`wp_get_unapproved_comment_author_email`](https://chugunov.pro/api-wordpress/functions/wp_get_unapproved_comment_author_email/), [`get_object_subtype`](https://chugunov.pro/api-wordpress/functions/get_object_subtype/), `WP_REST_Comments_Controller::get_comment`, `WP_REST_Comments_Controller::update_item`, `WP_REST_Comments_Controller::delete_item`, `WP_REST_Comments_Controller::create_item`, `WP_Comment_Query::fill_descendants`, [`wp_handle_comment_submission`](https://chugunov.pro/api-wordpress/functions/wp_handle_comment_submission/), [`wp_new_comment_notify_moderator`](https://chugunov.pro/api-wordpress/functions/wp_new_comment_notify_moderator/), [`wp_new_comment_notify_postauthor`](https://chugunov.pro/api-wordpress/functions/wp_new_comment_notify_postauthor/), `WP_Comments_List_Table::floated_admin_avatar`, `WP_Comment_Query::get_comments`, [`get_avatar_data`](https://chugunov.pro/api-wordpress/functions/get_avatar_data/), [`touch_time`](https://chugunov.pro/api-wordpress/functions/touch_time/), [`_wp_ajax_delete_comment_response`](https://chugunov.pro/api-wordpress/functions/_wp_ajax_delete_comment_response/), [`wp_ajax_delete_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_delete_comment/), [`wp_ajax_dim_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_dim_comment/), [`wp_ajax_get_comments`](https://chugunov.pro/api-wordpress/functions/wp_ajax_get_comments/), [`wp_ajax_replyto_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_replyto_comment/), [`wp_ajax_edit_comment`](https://chugunov.pro/api-wordpress/functions/wp_ajax_edit_comment/), `WP_Comments_List_Table::column_comment`, [`get_comment_to_edit`](https://chugunov.pro/api-wordpress/functions/get_comment_to_edit/), `WP_Comment`, [`floated_admin_avatar`](https://chugunov.pro/api-wordpress/functions/floated_admin_avatar/), [`map_meta_cap`](https://chugunov.pro/api-wordpress/functions/map_meta_cap/), [`get_avatar`](https://chugunov.pro/api-wordpress/functions/get_avatar/), [`wp_notify_postauthor`](https://chugunov.pro/api-wordpress/functions/wp_notify_postauthor/), [`wp_notify_moderator`](https://chugunov.pro/api-wordpress/functions/wp_notify_moderator/), [`get_commentdata`](https://chugunov.pro/api-wordpress/functions/get_commentdata/), [`wp_scheduled_delete`](https://chugunov.pro/api-wordpress/functions/wp_scheduled_delete/), [`get_edit_comment_link`](https://chugunov.pro/api-wordpress/functions/get_edit_comment_link/), [`edit_comment_link`](https://chugunov.pro/api-wordpress/functions/edit_comment_link/), [`get_comment_guid`](https://chugunov.pro/api-wordpress/functions/get_comment_guid/), `wp_xmlrpc_server::wp_deleteComment`, `wp_xmlrpc_server::wp_editComment`, `wp_xmlrpc_server::wp_getComment`, [`comment_form_title`](https://chugunov.pro/api-wordpress/functions/comment_form_title/), [`get_comment_reply_link`](https://chugunov.pro/api-wordpress/functions/get_comment_reply_link/), [`get_comment_link`](https://chugunov.pro/api-wordpress/functions/get_comment_link/).

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