shortcode to get user infos
This commit is contained in:
@@ -11,19 +11,50 @@ if (!defined('ABSPATH')) {
|
||||
|
||||
|
||||
/*
|
||||
* shortcode to write email of the logged in user
|
||||
* 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_email_shortcode() {
|
||||
$text_not_logged_in = "you are not logged in";
|
||||
if (is_user_logged_in()) {
|
||||
$current_user = wp_get_current_user();
|
||||
return $current_user->user_email;
|
||||
}
|
||||
else {
|
||||
return $text_not_logged_in;
|
||||
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_email', 'current_user_email_shortcode');
|
||||
add_shortcode('cipf_user_info', 'current_user_infos_CIPF');
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user