Usage
PHP
nebula()->get_user_info($datapoint, $options)
Parameters
$datapoint
(Optional) (String) The user meta name to retrieve
Default: None
$options
(Optional) (Array)
Default: None
Parameter Notes
$options include:
- ‘id’ (default:
get_current_user_id()) - ‘prepend’
- ‘append’
Examples
Append the user's email address in a query string if available
PHP
echo 'https://gearside.com/' . nebula()->get_user_info('user_email', array('prepend' => '&nv-email='))
Additional Notes
If a specific datapoint is not passed, the entire userdata object is returned. If the datapoint is not available it returns false.
Source File
Located in /libs/Functions.php on line 2438.
No Hooks
This function does not have any filters or actions available. Request one?
PHP
public function get_user_info($datapoint, $options=array()){
$defaults = array(
'id' => get_current_user_id(),
'datapoint' => $datapoint,
'fresh' => false,
'prepend' => '',
'append' => '',
'fallback' => false,
);
$data = array_merge($defaults, $options);
if ( empty($data['id']) ){ //If there is no user or current user is not logged in
return $data['fallback'];
}
//Try to get user data from the static variable (memoization within the current page load only)
static $memoized_user_data = array();
$cache_key = 'user-id-' . $data['id'];
if ( !empty($data['fresh']) || !isset($memoized_user_data[$cache_key]) ) {
//Fetch data from the database if not already memoized
$userdata = get_userdata($data['id']);
if ( !empty($userdata) ) {
//Memoize the user data for the current page load
$memoized_user_data[$cache_key] = $userdata;
}
} else {
//Get the memoized data if it was previously loaded in the same page request
$userdata = $memoized_user_data[$cache_key];
}
if ( !empty($data['datapoint']) ){
$requested_data = $data['datapoint'];
if ( !empty($userdata->$requested_data) ){
return $data['prepend'] . $userdata->$requested_data . $data['append'];
} else {
return $data['fallback'];
}
}
if ( !empty($userdata) ){
return $userdata;
}
return $data['fallback'];
}
Override
This function can not be short-circuited with an override filter. Request one?