简体   繁体   English

WordPress-获取当前用户详细信息

[英]Wordpress - get current user details

So I'm trying to write a function that is called when a new user registers that emails the admin with information about the new users account. 因此,我正在尝试编写一个新用户注册时调用的函数,该函数通过电子邮件向管理员发送有关新用户帐户的信息。

I am trying to do this with the get_currentuserinfo(); 我正在尝试使用get_currentuserinfo(); function but have been having no luck. 功能,但没有运气。 Below is the code I am currently using: 以下是我当前使用的代码:

// WooCommerce New Customer Admin Notification Email
function new_customer_registered_send_email_admin() {
    //variables
    global $current_user;
    get_currentuserinfo();
    $useremail = $current_user->user_email;
    $username = $current_user->user_login;
    $firstname = $current_user->user_firstname;
    $lastname = $current_user->user_lastname;

    wp_mail( 'email@domain.com', 'test', 'The user ' . $user_login .' created an account on the website. Email: ' . $useremail . ' );
}
add_action('new_customer_registered', 'new_customer_registered_send_email_admin');

Whilst the email comes through without an issue, the variables aren't printing. 尽管电子邮件通过没有问题,但变量没有打印出来。

add the following code and run it I'm sure you are testing it on the local server, not on live server otherwise print_r will display all the user info including emails password etc so you must try this on the local machine. 添加以下代码并运行它,我确定您是在本地服务器上测试它,而不是在实时服务器上测试它,否则print_r将显示所有用户信息,包括电子邮件密码等,因此您必须在本地计算机上尝试。

     function new_customer_registered_send_email_admin() {
//variables
global $current_user;
wp_get_current_user();
$useremail = $current_user->user_email;
$username = $current_user->user_login;
$firstname = $current_user->user_firstname;
$lastname = $current_user->user_lastname;

   print_r($current_user);exit;
   }
 add_action('wp_login', 'new_customer_registered_send_email_admin');

i'm sure this code will help you to debug what exactly you are looking for. 我确定这段代码将帮助您调试您要寻找的东西。

Thank You! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM