# get_comment_author_link()

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

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

## Сигнатура

```php
get_comment_author_link( int|WP_Comment $comment_id ): string
```

## Описание

И get_comment_author_url(), и get_comment_author() полагаются на get_comment(), который использует глобальную переменную комментария, если аргумент $comment_id пуст.

## Параметры

- `$comment_id` `int|WP_Comment` — необязательный. WP_Comment или идентификатор комментария, для которого нужно получить ссылку автора.
  
  По умолчанию — текущий комментарий.

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

`string`

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

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

```php
function get_comment_author_link( $comment_id = 0 ) {
	$comment = get_comment( $comment_id );

	if ( ! empty( $comment->comment_ID ) ) {
		$comment_id = $comment->comment_ID;
	} elseif ( is_scalar( $comment_id ) ) {
		$comment_id = (string) $comment_id;
	} else {
		$comment_id = '0';
	}

	$comment_author_url = get_comment_author_url( $comment );
	$comment_author     = get_comment_author( $comment );

	if ( empty( $comment_author_url ) || 'http://' === $comment_author_url ) {
		$comment_author_link = $comment_author;
	} else {
		$rel_parts = array( 'ugc' );
		if ( ! wp_is_internal_link( $comment_author_url ) ) {
			$rel_parts = array_merge(
				$rel_parts,
				array( 'external', 'nofollow' )
			);
		}

		/**
		 * Filters the rel attributes of the comment author's link.
		 *
		 * @since 6.2.0
		 *
		 * @param string[]   $rel_parts An array of strings representing the rel tags
		 *                              which will be joined into the anchor's rel attribute.
		 * @param WP_Comment $comment   The comment object.
		 */
		$rel_parts = apply_filters( 'comment_author_link_rel', $rel_parts, $comment );

		$rel = implode( ' ', $rel_parts );
		$rel = esc_attr( $rel );
		// Empty space before 'rel' is necessary for later sprintf().
		$rel = ! empty( $rel ) ? sprintf( ' rel="%s"', $rel ) : '';

		$comment_author_link = sprintf(
			'<a href="%1$s" class="url"%2$s>%3$s</a>',
			$comment_author_url,
			$rel,
			$comment_author
		);
	}

	/**
	 * Filters the comment author's link for display.
	 *
	 * @since 1.5.0
	 * @since 4.1.0 The `$comment_author` and `$comment_id` parameters were added.
	 *
	 * @param string $comment_author_link The HTML-formatted comment author link.
	 *                                    Empty for an invalid URL.
	 * @param string $comment_author      The comment author's username.
	 * @param string $comment_id          The comment ID as a numeric string.
	 */
	return apply_filters( 'get_comment_author_link', $comment_author_link, $comment_author, $comment_id );
}
```

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

- 4.4.0 — Added the ability for $comment_id to also accept a WP_Comment object.
- 1.5.0 — Introduced.

## Связанные

Использует: [`wp_is_internal_link`](https://chugunov.pro/api-wordpress/functions/wp_is_internal_link/), [`get_comment_author_url`](https://chugunov.pro/api-wordpress/functions/get_comment_author_url/), [`get_comment_author`](https://chugunov.pro/api-wordpress/functions/get_comment_author/), [`esc_attr`](https://chugunov.pro/api-wordpress/functions/esc_attr/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_comment`](https://chugunov.pro/api-wordpress/functions/get_comment/).
Используется в: [`_wp_dashboard_recent_comments_row`](https://chugunov.pro/api-wordpress/functions/_wp_dashboard_recent_comments_row/), `WP_Widget_Recent_Comments::widget`, `Walker_Comment::comment`, `Walker_Comment::html5_comment`, [`comment_author_link`](https://chugunov.pro/api-wordpress/functions/comment_author_link/).

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