您的当前位置:首页 > 知识博客 > wordpress建站

WordPress获取当前登录用户对象数据函数:wp_get_current_user

时间:2024-03-09

WordPress函数wp_get_current_user用于获取当前已登录用户的对象数据,该函数没有可用的参数。

wp_get_current_user()

函数返回值

wp_get_current_user()函数返回WP_User实例,包含了用户的各字段信息。

函数使用示例

$current_user = wp_get_current_user();
echo '用户名:' . $current_user->user_login . '<br >';
echo '邮箱:' . $current_user->user_email . '<br >';
echo '名字:' . $current_user->user_firstname . '<br >';
echo '姓氏:' . $current_user->user_lastname . '<br >';
echo '公开显示名称:' . $current_user->display_name . '<br >';
echo 'ID:' . $current_user->ID . '<br >';

扩展阅读

wp_get_current_user()函数位于:wp-includes/pluggable.php

相关函数:

  • wp_set_current_user()

  • wp_switch_roles_and_user()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 sex.cyou


Whatsapp
Powered by RRZCMS