get_comment_author() - WordPress 函数参考中文文档

返回介绍

get_comment_author()

发布于 2017-09-10 字数2660 浏览 605 评论 0

get_comment_author( int|WP_Comment $comment_ID )

Retrieve the author of the current comment.


描述

If the comment has an empty comment_author field, then ‘Anonymous’ person is assumed.


参数

$comment_ID

(int|WP_Comment)
(Optional)
WP_Comment or the ID of the comment for which to retrieve the author. Default current comment.


返回值

(string) The comment author


源代码

File: wp-includes/comment-template.php

function get_comment_author( $comment_ID = 0 ) {
	$comment = get_comment( $comment_ID );

	if ( empty( $comment->comment_author ) ) {
		if ( $comment->user_id && $user = get_userdata( $comment->user_id ) )
			$author = $user->display_name;
		else
			$author = __('Anonymous');
	} else {
		$author = $comment->comment_author;
	}

	/**
	 * Filters the returned comment author name.
	 *
	 * @since 1.5.0
	 * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added.
	 *
	 * @param string     $author     The comment author's username.
	 * @param int        $comment_ID The comment ID.
	 * @param WP_Comment $comment    The comment object.
	 */
	return apply_filters( 'get_comment_author', $author, $comment->comment_ID, $comment );
}

更新日志

Version 描述
4.4.0 Added the ability for $comment_ID to also accept a WP_Comment object.
1.5.0 Introduced.

相关函数

Uses

  • wp-includes/l10n.php:
    __()
  • wp-includes/pluggable.php:
    get_userdata()
  • wp-includes/plugin.php:
    apply_filters()
  • wp-includes/comment-template.php:
    get_comment_author
  • wp-includes/comment.php:
    get_comment()

Used By

  • wp-admin/includes/class-wp-comments-list-table.php:
    WP_Comments_List_Table::column_comment()
  • wp-includes/feed.php:
    get_comment_author_rss()
  • wp-includes/comment-template.php:
    comment_form_title()
  • wp-includes/comment-template.php:
    comment_author()
  • wp-includes/comment-template.php:
    get_comment_author_link()

User Contributed Notes

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!