61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
/*
|
|
* it means someone outside wp is accessing the file, in this case kill it.
|
|
*/
|
|
if (!defined('ABSPATH')) {
|
|
die('You can not access this file!');
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
* shortcode to write user info of the logged in user
|
|
* 0 or 1 argument, usage :
|
|
* - [cipf_user_info] -> list of all availables infos
|
|
* - [cipf_user_info user_email] -> display the email
|
|
* - [cipf_user_info user_email user_login] -> display the email
|
|
*/
|
|
function current_user_infos_CIPF($atts) {
|
|
if (!is_user_logged_in())
|
|
return ;
|
|
error_log("----");
|
|
|
|
$current_user = wp_get_current_user();
|
|
$current_user_infos = $current_user->data;
|
|
|
|
if (empty($atts)) {
|
|
$user_properties = (array) get_userdata($current_user->ID)->data;
|
|
$user_metas = get_user_meta($current_user->ID);
|
|
$user_infos = array_merge($user_metas, $user_properties);
|
|
$output = '<ul>';
|
|
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];
|
|
$output = $current_user->$query;
|
|
if (is_string($output))
|
|
return $output;
|
|
else
|
|
return json_encode($output);
|
|
}
|
|
add_shortcode('cipf_user_info', 'current_user_infos_CIPF');
|
|
|
|
|
|
?>
|