some improvments on shortcode user_info, to output the right secure string in most cases

This commit is contained in:
asus
2024-03-13 14:57:01 +01:00
parent 10ca070d81
commit 12de8ee12f

View File

@@ -39,20 +39,18 @@ function merge_two_arrays_CIPF($array1, $array2) {
}
function output_list_front_CIPF($array) {
function output_list_front_CIPF($array, $current_user, $user_id) {
PLGNTLS_class::debug_infos();
$output = '<ul>';
foreach ($array as $key => $value) {
if (str_starts_with($key, '_'))
continue ;
$value = format_user_info_CIPF($key, $current_user, $user_id);
$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 .= $value;
$output .= '</span>';
$output .= '</li>';
}
@@ -127,10 +125,13 @@ function format_user_info_CIPF($query, &$current_user, $user_id) {
* return the result
*
*/
if (is_string($output))
return $output;
else
return json_encode($output);
while (is_array($output) && count($output) === 1)
$output = reset($output);
if (is_array($output) && count($output) === 0)
$output = '';
if (!is_string($output))
$output = json_encode($output, JSON_UNESCAPED_SLASHES);
return esc_html($output);
}
@@ -217,7 +218,7 @@ function current_user_infos_CIPF($atts) {
$user_properties = (array) get_userdata($user_id)->data;
$user_metas = get_user_meta($user_id);
$user_infos = merge_two_arrays_CIPF($user_metas, $user_properties);
return output_list_front_CIPF($user_infos);
return output_list_front_CIPF($user_infos, $current_user, $user_id);
}
/*
@@ -226,7 +227,7 @@ function current_user_infos_CIPF($atts) {
*
*/
if (is_array($atts))
$query = reset($atts);
$query = $atts[0];
else if (is_string($atts))
$query = $atts;
else