bbp_filter_user_id

Filter the current bbPress user ID with the current BuddyPress user ID.

Description

(int) bbp_filter_user_id( (int) $user_id = 0, (constant) $displayed_user_fallback = true, (bool) $current_user_fallback = false ); 

Returns (int)

User ID

Parameters (3)

0. $user_id — Optional. (int)
The user id.
1. $displayed_user_fallback — Optional. (constant) => true
The displayed user fallback.
2. $current_user_fallback — Optional. (bool) => false
The current user fallback.

Usage

  1. if ( !function_exists( 'bbp_filter_user_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/extend/buddypress/functions.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // The displayed user fallback. 
  8. $displayed_user_fallback = true; 
  9.  
  10. // The current user fallback. 
  11. $current_user_fallback = false; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = bbp_filter_user_id($user_id, $displayed_user_fallback, $current_user_fallback); 
  15.  

Defined (1)

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

/includes/extend/buddypress/functions.php  
  1. function bbp_filter_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) { 
  2.  
  3. // Define local variable 
  4. $bbp_user_id = 0; 
  5.  
  6. // Get possible user ID's 
  7. $did = bp_displayed_user_id(); 
  8. $lid = bp_loggedin_user_id(); 
  9.  
  10. // Easy empty checking 
  11. if ( !empty( $user_id ) && is_numeric( $user_id ) ) 
  12. $bbp_user_id = $user_id; 
  13.  
  14. // Currently viewing or editing a user 
  15. elseif ( ( true === $displayed_user_fallback ) && !empty( $did ) ) 
  16. $bbp_user_id = $did; 
  17.  
  18. // Maybe fallback on the current_user ID 
  19. elseif ( ( true === $current_user_fallback ) && !empty( $lid ) ) 
  20. $bbp_user_id = $lid; 
  21.  
  22. return $bbp_user_id;