# wp_dashboard_recent_comments()

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

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

## Сигнатура

```php
wp_dashboard_recent_comments( int $total_items = 5 ): bool
```

## Описание

Показывает раздел комментариев.

## Параметры

- `$total_items` `int` — необязательный, по умолчанию `5`. Число комментариев для запроса.

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

`bool`

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

Файл: `wp-admin/includes/dashboard.php:1075`

```php
function wp_dashboard_recent_comments( $total_items = 5 ) {
	// Select all comment types and filter out spam later for better query performance.
	$comments = array();

	$comments_query = array(
		'number' => $total_items * 5,
		'offset' => 0,
	);

	if ( ! current_user_can( 'edit_posts' ) ) {
		$comments_query['status'] = 'approve';
	}

	$comments_count = 0;
	do {
		$possible = get_comments( $comments_query );

		if ( empty( $possible ) || ! is_array( $possible ) ) {
			break;
		}

		foreach ( $possible as $comment ) {
			if ( ! current_user_can( 'edit_post', $comment->comment_post_ID )
				&& ( post_password_required( $comment->comment_post_ID )
					|| ! current_user_can( 'read_post', $comment->comment_post_ID ) )
			) {
				// The user has no access to the post and thus cannot see the comments.
				continue;
			}

			$comments[]     = $comment;
			$comments_count = count( $comments );

			if ( $comments_count === $total_items ) {
				break 2;
			}
		}

		$comments_query['offset'] += $comments_query['number'];
		$comments_query['number']  = $total_items * 10;
	} while ( $comments_count < $total_items );

	if ( $comments ) {
		echo '<div id="latest-comments" class="activity-block table-view-list">';
		echo '<h3>' . __( 'Recent Comments' ) . '</h3>';

		echo '<ul id="the-comment-list" data-wp-lists="list:comment">';
		foreach ( $comments as $comment ) {
			_wp_dashboard_recent_comments_row( $comment );
		}
		echo '</ul>';

		if ( current_user_can( 'edit_posts' ) ) {
			echo '<h3 class="screen-reader-text">' .
				/* translators: Hidden accessibility text. */
				__( 'View more comments' ) .
			'</h3>';
			_get_list_table( 'WP_Comments_List_Table' )->views();
		}

		wp_comment_reply( -1, false, 'dashboard', false );
		wp_comment_trashnotice();

		echo '</div>';
	} else {
		return false;
	}
	return true;
}
```

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

- 3.8.0 — Introduced.

## Связанные

Использует: [`_wp_dashboard_recent_comments_row`](https://chugunov.pro/api-wordpress/functions/_wp_dashboard_recent_comments_row/), [`_get_list_table`](https://chugunov.pro/api-wordpress/functions/_get_list_table/), `WP_List_Table`, [`wp_comment_reply`](https://chugunov.pro/api-wordpress/functions/wp_comment_reply/), [`wp_comment_trashnotice`](https://chugunov.pro/api-wordpress/functions/wp_comment_trashnotice/), [`post_password_required`](https://chugunov.pro/api-wordpress/functions/post_password_required/), [`get_comments`](https://chugunov.pro/api-wordpress/functions/get_comments/), [`current_user_can`](https://chugunov.pro/api-wordpress/functions/current_user_can/), [`__`](https://chugunov.pro/api-wordpress/functions/__/).
Используется в: [`wp_dashboard_site_activity`](https://chugunov.pro/api-wordpress/functions/wp_dashboard_site_activity/).

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