bp_get_friendship_requests

Get a user's friendship requests.

Description

(array|int) bp_get_friendship_requests( (int) $user_id = 0 ); 

Note that we return a 0 if no pending requests are found. This is necessary because of the structure of the $include parameter in bp_has_members().

Returns (array|int)

An array of user IDs if found, or a 0 if none are found.

Parameters (1)

0. $user_id — Optional. (int)
ID of the user whose requests are being retrieved. Defaults to displayed user.

Usage

  1. if ( !function_exists( 'bp_get_friendship_requests' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'buddypress/bp-friends/bp-friends-template.php'; 
  3.  
  4. // ID of the user whose requests are being retrieved. 
  5. // Defaults to displayed user. 
  6. $user_id = -1; 
  7.  
  8. // NOTICE! Understand what this does before running. 
  9. $result = bp_get_friendship_requests($user_id); 
  10.  

Defined (1)

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

/bp-friends/bp-friends-template.php  
  1. function bp_get_friendship_requests( $user_id = 0 ) { 
  2. if ( !$user_id ) { 
  3. $user_id = bp_displayed_user_id(); 
  4.  
  5. if ( !$user_id ) { 
  6. return 0; 
  7.  
  8. $requests = friends_get_friendship_request_user_ids( $user_id ); 
  9.  
  10. if ( !empty( $requests ) ) { 
  11. $requests = implode( ', ', (array) $requests ); 
  12. } else { 
  13. $requests = 0; 
  14.  
  15. /** 
  16. * Filters the total pending friendshiprequestsfor a user. 
  17. * @since 1.2.0 
  18. * @since 2.6.0 Added the `$user_id` parameter. 
  19. * @param array|int $requests An array of user IDs if found, or a 0 if none are found. 
  20. * @param int $user_id ID of the queried user. 
  21. */ 
  22. return apply_filters( 'bp_get_friendship_requests', $requests, $user_id );