bp_get_member_name

Get the display name of the current member in the loop.

Description

(string) bp_get_member_name(); 

Full name is, by default, pulled from xprofile's Full Name field. When this field is empty, we try to get an alternative name from the WP users table, in the following order of preference: display_name, user_nicename, user_login.

Returns (string)

The user's fullname for display.


Usage

  1. if ( !function_exists( 'bp_get_member_name' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-members/bp-members-template.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = bp_get_member_name(); 
  7.  

Defined (1)

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

/bp-members/bp-members-template.php  
  1. function bp_get_member_name() { 
  2. global $members_template; 
  3.  
  4. // Generally, this only fires when xprofile is disabled. 
  5. if ( empty( $members_template->member->fullname ) ) { 
  6. // Our order of preference for alternative fullnames. 
  7. $name_stack = array( 
  8. 'display_name',  
  9. 'user_nicename',  
  10. 'user_login' 
  11. ); 
  12.  
  13. foreach ( $name_stack as $source ) { 
  14. if ( !empty( $members_template->member->{$source} ) ) { 
  15. // When a value is found, set it as fullname and be done with it. 
  16. $members_template->member->fullname = $members_template->member->{$source}; 
  17. break; 
  18.  
  19. /** 
  20. * Filters the display name of current member in the loop. 
  21. * @since 1.2.0 
  22. * @param string $fullname Display name for current member. 
  23. */ 
  24. return apply_filters( 'bp_get_member_name', $members_template->member->fullname );