bp_core_get_userlink

Return a HTML formatted link for a user with the user's full name as the link text.

Description

(string|bool) bp_core_get_userlink( (int) $user_id, (constant) $no_anchor = false, (bool) $just_link = false ); 

Eg: Andy Peatling

Optional parameters will return just the name or just the URL.

Returns (string|bool)

The link text based on passed parameters, or false on no match.

Parameters (3)

0. $user_id (int)
User ID to check.
1. $no_anchor — Optional. (constant) => false
Disable URL and HTML and just return full name. Default: false.
2. $just_link — Optional. (bool) => false
Disable full name and HTML and just return the URL text. Default false.

Usage

  1. if ( !function_exists( 'bp_core_get_userlink' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-functions.php'; 
  3.  
  4. // User ID to check. 
  5. $user_id = -1; 
  6.  
  7. // Disable URL and HTML and just return full name. 
  8. // Default: false. 
  9. $no_anchor = false; 
  10.  
  11. // Disable full name and HTML and just return the URL 
  12. // text. Default false. 
  13. $just_link = false; 
  14.  
  15. // NOTICE! Understand what this does before running. 
  16. $result = bp_core_get_userlink($user_id, $no_anchor, $just_link); 
  17.  

Defined (1)

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

/bp-members/bp-members-functions.php  
  1. function bp_core_get_userlink( $user_id, $no_anchor = false, $just_link = false ) { 
  2. $display_name = bp_core_get_user_displayname( $user_id ); 
  3.  
  4. if ( empty( $display_name ) ) { 
  5. return false; 
  6.  
  7. if ( ! empty( $no_anchor ) ) { 
  8. return $display_name; 
  9.  
  10. if ( !$url = bp_core_get_user_domain( $user_id ) ) { 
  11. return false; 
  12.  
  13. if ( ! empty( $just_link ) ) { 
  14. return $url; 
  15.  
  16. /** 
  17. * Filters the link text for the passed in user. 
  18. * @since 1.2.0 
  19. * @param string $value Link text based on passed parameters. 
  20. * @param int $user_id ID of the user to check. 
  21. */ 
  22. return apply_filters( 'bp_core_get_userlink', '<a href="' . $url . '">' . $display_name . '</a>', $user_id );