shortcode to get user infos

This commit is contained in:
asus
2024-03-03 01:37:10 +01:00
parent 8862bab1bd
commit cae80d7d24
3 changed files with 43 additions and 12 deletions

View File

@@ -37,7 +37,7 @@ include_once(PLGNTLS_class::get_path() . 'php/admin_menu/example_menu.php');
include_once(PLGNTLS_class::get_path() . 'php/paypal/paypal.php');
//include_once(PLGNTLS_class::get_path() . '/php/user_infos.php');
include_once(PLGNTLS_class::get_path() . '/php/user_infos.php');
//include_once(PLGNTLS_class::get_path() . '/php/hide_admin.php');
//include_once(PLGNTLS_class::get_path() . '/php/menus.php');
include_once(PLGNTLS_class::get_path() . 'php/register_partenaires.php');

View File

@@ -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');
?>

Submodule private updated: 9eb05bf82c...a25574e7f7