bbp_get_author_link

Return the author link of the post.

Description

(string) bbp_get_author_link( (string) $args = '' ); 

Returns (string)

Author link of reply

Parameters (1)

0. $args — Optional. (string) => ''
If an integer, it is used as reply id.

Usage

  1. if ( !function_exists( 'bbp_get_author_link' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // Optional. If an integer, it is used as reply id. 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bbp_get_author_link($args); 
  9.  

Defined (1)

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

/includes/users/template.php  
  1. function bbp_get_author_link( $args = '' ) { 
  2.  
  3. $post_id = is_numeric( $args ) ? (int) $args : 0; 
  4.  
  5. // Parse arguments against default values 
  6. $r = bbp_parse_args( $args, array( 
  7. 'post_id' => $post_id,  
  8. 'link_title' => '',  
  9. 'type' => 'both',  
  10. 'size' => 80 
  11. ), 'get_author_link' ); 
  12.  
  13. // Confirmed topic 
  14. if ( bbp_is_topic( $r['post_id'] ) ) { 
  15. return bbp_get_topic_author_link( $r ); 
  16.  
  17. // Confirmed reply 
  18. } elseif ( bbp_is_reply( $r['post_id'] ) ) { 
  19. return bbp_get_reply_author_link( $r ); 
  20.  
  21. // Get the post author and proceed 
  22. $user_id = get_post_field( 'post_author', $r['post_id'] ); 
  23.  
  24. // Neither a reply nor a topic, so could be a revision 
  25. if ( !empty( $r['post_id'] ) ) { 
  26.  
  27. // Generate title with the display name of the author 
  28. if ( empty( $r['link_title'] ) ) { 
  29. $r['link_title'] = sprintf( !bbp_is_reply_anonymous( $r['post_id'] ) ? __( 'View %s\'s profile', bbpress ) : __( 'Visit %s\'s website', bbpress ), get_the_author_meta( 'display_name', $user_id ) ); 
  30.  
  31. // Assemble some link bits 
  32. $link_title = !empty( $r['link_title'] ) ? ' title="' . $r['link_title'] . '"' : ''; 
  33. $anonymous = bbp_is_reply_anonymous( $r['post_id'] ); 
  34.  
  35. // Get avatar 
  36. if ( 'avatar' === $r['type'] || 'both' === $r['type'] ) { 
  37. $author_links[] = get_avatar( $user_id, $r['size'] ); 
  38.  
  39. // Get display name 
  40. if ( 'name' === $r['type'] || 'both' === $r['type'] ) { 
  41. $author_links[] = get_the_author_meta( 'display_name', $user_id ); 
  42.  
  43. // Add links if not anonymous 
  44. if ( empty( $anonymous ) && bbp_user_has_profile( $user_id ) ) { 
  45. $author_url = bbp_get_user_profile_url( $user_id ); 
  46. foreach ( $author_links as $link_text ) { 
  47. $author_link[] = sprintf( '<a href="%1$s"%2$s>%3$s</a>', $author_url, $link_title, $link_text ); 
  48. $author_link = implode( ' ', $author_link ); 
  49.  
  50. // No links if anonymous 
  51. } else { 
  52. $author_link = implode( ' ', $author_links ); 
  53.  
  54. // No post so link is empty 
  55. } else { 
  56. $author_link = ''; 
  57.  
  58. return apply_filters( 'bbp_get_author_link', $author_link, $r );