bp_get_member_class

Return the row class of the current member in the loop.

Description

(string) bp_get_member_class( (array) $classes = array() ); 

Returns (string)

Row class of the member

Parameters (1)

0. $classes — Optional. (array) => array()
Array of custom classes.

Usage

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

Defined (1)

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

/bp-members/bp-members-template.php  
  1. function bp_get_member_class( $classes = array() ) { 
  2. global $members_template; 
  3.  
  4. // Add even/odd classes, but only if there's more than 1 member. 
  5. if ( $members_template->member_count > 1 ) { 
  6. $pos_in_loop = (int) $members_template->current_member; 
  7. $classes[] = ( $pos_in_loop % 2 ) ? 'even' : 'odd'; 
  8.  
  9. // If we've only one member in the loop, don't bother with odd and even. 
  10. } else { 
  11. $classes[] = 'bp-single-member'; 
  12.  
  13. // Maybe add 'is-online' class. 
  14. if ( ! empty( $members_template->member->last_activity ) ) { 
  15.  
  16. // Calculate some times. 
  17. $current_time = bp_core_current_time( true, 'timestamp' ); 
  18. $last_activity = strtotime( $members_template->member->last_activity ); 
  19. $still_online = strtotime( '+5 minutes', $last_activity ); 
  20.  
  21. // Has the user been active recently? 
  22. if ( $current_time <= $still_online ) { 
  23. $classes[] = 'is-online'; 
  24.  
  25. // Add current user class. 
  26. if ( bp_loggedin_user_id() === (int) $members_template->member->id ) { 
  27. $classes[] = 'is-current-user'; 
  28.  
  29. // Add current user member types. 
  30. if ( $member_types = bp_get_member_type( $members_template->member->id, false ) ) { 
  31. foreach ( $member_types as $member_type ) { 
  32. $classes[] = sprintf( 'member-type-%s', esc_attr( $member_type ) ); 
  33.  
  34. /** 
  35. * Filters the determined classes to add to the HTML element. 
  36. * @since 1.7.0 
  37. * @param string $classes Classes to be added to the HTML element. 
  38. */ 
  39. $classes = apply_filters( 'bp_get_member_class', $classes ); 
  40. $classes = array_merge( $classes, array() ); 
  41. $retval = 'class="' . join( ' ', $classes ) . '"'; 
  42.  
  43. return $retval;