get_comment_author

Retrieve the author of the current comment.

Description

(string) get_comment_author( (int) $comment_ID = 0 ); 

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

Returns (string)

The comment author

Parameters (1)

0. $comment_id — Optional. (int)
WP_Comment or the ID of the comment for which to retrieve the author.

Usage

  1. if ( !function_exists( 'get_comment_author' ) ) { 
  2. require_once ABSPATH . WPINC . '/comment-template.php'; 
  3.  
  4. // Optional. WP_Comment or the ID of the comment for which to retrieve the author. 
  5. // Default current comment. 
  6. $comment_id = -1; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = get_comment_author($comment_id); 
  10.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/comment-template.php  
  1. function get_comment_author( $comment_ID = 0 ) { 
  2. $comment = get_comment( $comment_ID ); 
  3.  
  4. if ( empty( $comment->comment_author ) ) { 
  5. if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) 
  6. $author = $user->display_name; 
  7. else 
  8. $author = __('Anonymous'); 
  9. } else { 
  10. $author = $comment->comment_author; 
  11.  
  12. /** 
  13. * Filters the returned comment author name. 
  14. * @since 1.5.0 
  15. * @since 4.1.0 The `$comment_ID` and `$comment` parameters were added. 
  16. * @param string $author The comment author's username. 
  17. * @param int $comment_ID The comment ID. 
  18. * @param WP_Comment $comment The comment object. 
  19. */ 
  20. return apply_filters( 'get_comment_author', $author, $comment->comment_ID, $comment );