bp_friends_get_profile_stats

Return the number of friends in user's profile.

Description

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

Returns (string)

HTML for stats output.

Parameters (1)

0. $args — Optional. (string) => ''
Before|after|user_id.

Usage

  1. if ( !function_exists( 'bp_friends_get_profile_stats' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-template.php'; 
  3.  
  4. // before|after|user_id. 
  5. $args = ''; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = bp_friends_get_profile_stats($args); 
  9.  

Defined (1)

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

/bp-friends/bp-friends-template.php  
  1. function bp_friends_get_profile_stats( $args = '' ) { 
  2.  
  3. // Parse the args. 
  4. $r = bp_parse_args( $args, array( 
  5. 'before' => '<li class="bp-friends-profile-stats">',  
  6. 'after' => '</li>',  
  7. 'user_id' => bp_displayed_user_id(),  
  8. 'friends' => 0,  
  9. 'output' => '' 
  10. ), 'friends_get_profile_stats' ); 
  11.  
  12. // Allow completely overloaded output. 
  13. if ( empty( $r['output'] ) ) { 
  14.  
  15. // Only proceed if a user ID was passed. 
  16. if ( ! empty( $r['user_id'] ) ) { 
  17.  
  18. // Get the user's friends. 
  19. if ( empty( $r['friends'] ) ) { 
  20. $r['friends'] = absint( friends_get_total_friend_count( $r['user_id'] ) ); 
  21.  
  22. // If friends exist, show some formatted output. 
  23. $r['output'] = $r['before'] . sprintf( _n( '%s friend', '%s friends', $r['friends'], buddypress ), '<strong>' . $r['friends'] . '</strong>' ) . $r['after']; 
  24.  
  25. /** 
  26. * Filters the number of friends in user's profile. 
  27. * @since 2.0.0 
  28. * @param string $value Formatted string displaying total friends count. 
  29. * @param array $r Array of arguments for string formatting and output. 
  30. */ 
  31. return apply_filters( 'bp_friends_get_profile_stats', $r['output'], $r );