function global_filter_user_profile_field in Views Global Filter 7
Same name and namespace in other branches
- 8 global_filter.module \global_filter_user_profile_field()
- 6 global_filter.module \global_filter_user_profile_field()
Retrieve the supplied field value(s) from the user profile.
2 calls to global_filter_user_profile_field()
- global_filter_user_login in ./
global_filter.module - Implements hook_user_login().
- global_filter_user_profile_form_submit in ./
global_filter.module - Additional handler for when the user_profile_form is submitted.
File
- ./
global_filter.module, line 164 - global_filter.module
Code
function global_filter_user_profile_field($field_name, $account = NULL) {
global $user;
if (empty($account)) {
$account = $user;
}
// The first occurrence of field_name, on either one of their profile2 or core
// user profiles will be used to return field values from.
if (module_exists('profile2')) {
$profiles = profile2_load_by_user($account);
foreach ($profiles as $profile) {
if ($items = field_get_items('profile2', $profile, $field_name)) {
break;
}
}
}
if (empty($items)) {
$account = user_load($account->uid);
// To also load core profile fields.
$items = field_get_items('user', $account, $field_name);
}
if (empty($items)) {
return NULL;
}
$field_values = array();
foreach ($items as $value) {
$field_values[] = isset($value['value']) ? $value['value'] : reset($value);
}
return count($field_values) > 1 ? $field_values : reset($field_values);
}