bbp_get_displayed_user_field

Return a sanitized user field value.

Description

(string|bool) bbp_get_displayed_user_field( (string) $field = '', (string) $filter = 'display' ); 

This function relies on the $filter parameter to decide how to sanitize the field value that it finds. Since it uses the WP_User object's magic __get() method, it can also be used to get user_meta values.

Returns (string|bool)

Value of the field if it exists, else false

Parameters (2)

0. $field — Optional. (string) => ''
Field to get
1. $filter — Optional. (string) => 'display'
How to filter the field value (null|raw|db|display|edit)

Usage

  1. if ( !function_exists( 'bbp_get_displayed_user_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'bbpress/includes/users/template.php'; 
  3.  
  4. // Field to get 
  5. $field = ''; 
  6.  
  7. // How to filter the field value (null|raw|db|display|edit) 
  8. $filter = 'display'; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = bbp_get_displayed_user_field($field, $filter); 
  12.  

Defined (1)

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

/includes/users/template.php  
  1. function bbp_get_displayed_user_field( $field = '', $filter = 'display' ) { 
  2.  
  3. // Get the displayed user 
  4. $user =bbpress)->displayed_user; 
  5.  
  6. // Juggle the user filter property because we don't want to muck up how 
  7. // other code might interact with this object. 
  8. $old_filter = $user->filter; 
  9. $user->filter = $filter; 
  10.  
  11. // Get the field value from the WP_User object. We don't need to perform 
  12. // an isset() because the WP_User::__get() does it for us. 
  13. $value = $user->$field; 
  14.  
  15. // Put back the user filter property that was previously juggled above. 
  16. $user->filter = $old_filter; 
  17.  
  18. // Return empty 
  19. return apply_filters( 'bbp_get_displayed_user_field', $value, $field, $filter );