small improvement in print user infos list
This commit is contained in:
@@ -7,7 +7,55 @@ if (!defined('ABSPATH')) {
|
|||||||
die('You can not access this file!');
|
die('You can not access this file!');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extract_if_array_size_one_CIPF($value) {
|
||||||
|
if (is_array($value) && count($value) === 1)
|
||||||
|
return reset($value);
|
||||||
|
return $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
function merge_two_arrays_CIPF($array1, $array2) {
|
||||||
|
$new_array = $array1;
|
||||||
|
foreach ($array2 as $key2 => $value2) {
|
||||||
|
$value = extract_if_array_size_one_CIPF($value2);
|
||||||
|
// if key was not in first array, add the new element to it
|
||||||
|
if (!isset($new_array[$key2])) {
|
||||||
|
$new_array[$key2] = $value2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// if key was in first array, add both in an array
|
||||||
|
$value1 = extract_if_array_size_one_CIPF($new_array[$key2]);
|
||||||
|
if (empty($value1))
|
||||||
|
$new_array[$key2] = $value2;
|
||||||
|
else if (empty($value2))
|
||||||
|
$new_array[$key2] = $value1;
|
||||||
|
else {
|
||||||
|
$new_value = array($value1, $value2);
|
||||||
|
$new_array[$key] = $new_value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $new_array;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function output_list_front_CIPF($array) {
|
||||||
|
$output = '<ul>';
|
||||||
|
foreach ($array as $key => $value) {
|
||||||
|
if (str_starts_with($key, '_'))
|
||||||
|
continue ;
|
||||||
|
$output .= '<li>';
|
||||||
|
$output .= '<span>';
|
||||||
|
$output .= $key;
|
||||||
|
$output .= ' : ';
|
||||||
|
if (is_array($value) && count($value) === 1)
|
||||||
|
$output .= json_encode($value[0]);
|
||||||
|
else
|
||||||
|
$output .= json_encode($value);
|
||||||
|
$output .= '</span>';
|
||||||
|
$output .= '</li>';
|
||||||
|
}
|
||||||
|
$output .= '</ul>';
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -28,24 +76,8 @@ function current_user_infos_CIPF($atts) {
|
|||||||
if (empty($atts)) {
|
if (empty($atts)) {
|
||||||
$user_properties = (array) get_userdata($current_user->ID)->data;
|
$user_properties = (array) get_userdata($current_user->ID)->data;
|
||||||
$user_metas = get_user_meta($current_user->ID);
|
$user_metas = get_user_meta($current_user->ID);
|
||||||
$user_infos = array_merge($user_metas, $user_properties);
|
$user_infos = merge_two_arrays_CIPF($user_metas, $user_properties);
|
||||||
$output = '<ul>';
|
return output_list_front_CIPF($user_infos);
|
||||||
foreach ($user_infos as $key => $value) {
|
|
||||||
if (str_starts_with($key, '_'))
|
|
||||||
continue ;
|
|
||||||
$output .= '<li>';
|
|
||||||
$output .= '<span>';
|
|
||||||
$output .= $key;
|
|
||||||
$output .= ' : ';
|
|
||||||
if (is_array($value) && count($value) === 1)
|
|
||||||
$output .= json_encode($value[0]);
|
|
||||||
else
|
|
||||||
$output .= json_encode($value);
|
|
||||||
$output .= '</span>';
|
|
||||||
$output .= '</li>';
|
|
||||||
}
|
|
||||||
$output .= '</ul>';
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
$query = $atts[0];
|
$query = $atts[0];
|
||||||
$output = $current_user->$query;
|
$output = $current_user->$query;
|
||||||
|
|||||||
Reference in New Issue
Block a user