xprofile_get_field_data
Fetches profile data for a specific field for the user.
Description
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
if ( !function_exists( 'xprofile_get_field_data' ) ) { require_once '/bp-xprofile/bp-xprofile-functions.php'; } // The ID of the field, or the $name of the field. $field = null; // The ID of the user. $user_id = -1; // How should array data be returned? 'comma' if you want a // comma-separated string; 'array' if you want an array. $multi_format = 'array'; // NOTICE! Understand what this does before running. $result = xprofile_get_field_data($field, $user_id, $multi_format);
Defined (1)
The function is defined in the following location(s).
- /bp-xprofile/bp-xprofile-functions.php
- function xprofile_get_field_data( $field, $user_id = 0, $multi_format = 'array' ) {
- if ( empty( $user_id ) ) {
- $user_id = bp_displayed_user_id();
- }
- if ( empty( $user_id ) ) {
- return false;
- }
- if ( is_numeric( $field ) ) {
- $field_id = $field;
- } else {
- $field_id = xprofile_get_field_id_from_name( $field );
- }
- if ( empty( $field_id ) ) {
- return false;
- }
- $values = maybe_unserialize( BP_XProfile_ProfileData::get_value_byid( $field_id, $user_id ) );
- if ( is_array( $values ) ) {
- $data = array();
- foreach( (array) $values as $value ) {
- /**
- * Filters the field data value for a specific field for the user.
- *
- * @since 1.0.0
- *
- * @param string $value Value saved for the field.
- * @param int $field_id ID of the field being displayed.
- * @param int $user_id ID of the user being displayed.
- */
- $data[] = apply_filters( 'xprofile_get_field_data', $value, $field_id, $user_id );
- }
- if ( 'comma' == $multi_format ) {
- $data = implode( ', ', $data );
- }
- } else {
- /** This filter is documented in bp-xprofile/bp-xprofile-functions.php */
- $data = apply_filters( 'xprofile_get_field_data', $values, $field_id, $user_id );
- }
- return $data;
- }