[英]How to get WordPress user role to show in new user notification email
I'm trying to modify the wordpress new user notification email to admin, using a bit of code someone else shared on here. 我正在尝试使用其他人在此处共享的一些代码将wordpress新用户通知电子邮件修改为admin。 Here's what I have added to it, but in the new user notification email it displays: "Role: Array" instead of the role value.
这是我添加的内容,但是在新的用户通知电子邮件中,它显示:“角色:数组”而不是角色值。 Any suggestions on how to get it to show the role value?
关于如何使其显示角色价值的任何建议?
<?php
/*
Plugin Name: Custom New User Email
Description: Changes the copy in the email sent out to new users
*/
// Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$user_info = get_userdata(1);
$message = sprintf(__('New user registration on %s:'), get_option('blogname')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n\r\n";
$message .= sprintf(__('Role: %s'), $user_info->roles) . "\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
}
}
?>
FYI, I figured it out and decided to post as an answer in case anyone is interested in adding this to the new user notification email (to admin only): 仅供参考,我想出了办法,决定将它发布为答案,以防万一有人有兴趣将其添加到新的用户通知电子邮件中(仅限管理员):
<?php
/*
Plugin Name: Custom New User Email
Description: Changes the copy in the email sent out to new users
*/
// Redefine user notification function
if ( !function_exists('wp_new_user_notification') ) {
function wp_new_user_notification( $user_id, $plaintext_pass = '' ) {
$user = new WP_User($user_id);
$user_login = stripslashes($user->user_login);
$user_email = stripslashes($user->user_email);
$user_meta = get_userdata($user_id);
$user_roles = $user_meta->roles;
$message = sprintf(__('New user registration on %s:'), get_option('blogname')) . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= sprintf(__('E-mail: %s'), $user_email) . "\r\n\r\n";
$message .= sprintf(__('Role: %s'), implode(', ',$user_meta->roles)) . "\n";
@wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), get_option('blogname')), $message);
if ( empty($plaintext_pass) )
return;
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.