xprofile_get_field_data

Fetches profile data for a specific field for the user.

Description

xprofile_get_field_data( (mixed) $field, (int) $user_id = 0, (string) $multi_format = 'array' ); 

When the field value is serialized, this function unserializes and filters each item in the array.

Parameters (3)

0. $field (mixed)
The ID of the field, or the $name of the field.
1. $user_id — Optional. (int)
The ID of the user.
2. $multi_format — Optional. (string) => 'array'
How should array data be returned? comma if you want a comma-separated string; array if you want an array.

Usage

  1. if ( !function_exists( 'xprofile_get_field_data' ) ) { 
  2. require_once '/bp-xprofile/bp-xprofile-functions.php'; 
  3.  
  4. // The ID of the field, or the $name of the field. 
  5. $field = null; 
  6.  
  7. // The ID of the user. 
  8. $user_id = -1; 
  9.  
  10. // How should array data be returned? 'comma' if you want a 
  11. // comma-separated string; 'array' if you want an array. 
  12. $multi_format = 'array'; 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = xprofile_get_field_data($field, $user_id, $multi_format); 
  16.  

Defined (1)

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

/bp-xprofile/bp-xprofile-functions.php  
  1. function xprofile_get_field_data( $field, $user_id = 0, $multi_format = 'array' ) { 
  2.  
  3. if ( empty( $user_id ) ) { 
  4. $user_id = bp_displayed_user_id(); 
  5.  
  6. if ( empty( $user_id ) ) { 
  7. return false; 
  8.  
  9. if ( is_numeric( $field ) ) { 
  10. $field_id = $field; 
  11. } else { 
  12. $field_id = xprofile_get_field_id_from_name( $field ); 
  13.  
  14. if ( empty( $field_id ) ) { 
  15. return false; 
  16.  
  17. $values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) ); 
  18.  
  19. if ( is_array( $values ) ) { 
  20. $data = array(); 
  21. foreach( (array) $values as $value ) { 
  22.  
  23. /** 
  24. * Filters the field data value for a specific field for the user. 
  25. * @since 1.0.0 
  26. * @param string $value Value saved for the field. 
  27. * @param int $field_id ID of the field being displayed. 
  28. * @param int $user_id ID of the user being displayed. 
  29. */ 
  30. $data[] = apply_filters( 'xprofile_get_field_data', $value, $field_id, $user_id ); 
  31.  
  32. if ( 'comma' == $multi_format ) { 
  33. $data = implode( ', ', $data ); 
  34. } else { 
  35. /** This filter is documented in bp-xprofile/bp-xprofile-functions.php */ 
  36. $data = apply_filters( 'xprofile_get_field_data', $values, $field_id, $user_id ); 
  37.  
  38. return $data;