bbp_get_user_id

Return a validated user id.

Description

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

Returns (int)

Validated user id

Parameters (3)

0. $user_id — Optional. (int)
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_get_user_id' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // Optional. 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_get_user_id($user_id, $displayed_user_fallback, $current_user_fallback); 
  15.  

Defined (1)

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

/includes/users/template.php  
  1. function bbp_get_user_id( $user_id = 0, $displayed_user_fallback = true, $current_user_fallback = false ) { 
  2. $bbp =bbpress); 
  3.  
  4. // Easy empty checking 
  5. if ( !empty( $user_id ) && is_numeric( $user_id ) ) { 
  6. $bbp_user_id = $user_id; 
  7.  
  8. // Currently viewing or editing a user 
  9. } elseif ( ( true === $displayed_user_fallback ) && !empty( $bbp->displayed_user->ID ) ) { 
  10. $bbp_user_id = $bbp->displayed_user->ID; 
  11.  
  12. // Maybe fallback on the current_user ID 
  13. } elseif ( ( true === $current_user_fallback ) && !empty( $bbp->current_user->ID ) ) { 
  14. $bbp_user_id = $bbp->current_user->ID; 
  15.  
  16. // Failsafe 
  17. } else { 
  18. $bbp_user_id = 0; 
  19.  
  20. return (int) apply_filters( 'bbp_get_user_id', (int) $bbp_user_id, $displayed_user_fallback, $current_user_fallback );