你会陷入profile_update
和user_register
. 首先检查是否是新用户,以及她是否是管理员/编辑。
然后发送邮件。更新用户的情况也一样:查看角色是否已更改,以及新角色是admin还是editor。
<?php
add_action( \'profile_update\', \'wpse33949_profile_update\' );
add_action( \'user_register\', \'wpse33949_profile_update\' );
function wpse33949_profile_update( $user_id, $old_user_data = false )
{
// get the updated user data
$userdata = get_userdata( $user_id );
// whatever you need to send here
$message = "Sign up for my email!";
$subject = "Mailing List";
if( ! $old_user_data && in_array( $userdata->user_role, array( \'editor\', \'administrator\' ) ) )
{
// we\'re inserting a new user...
wp_mail( $userdata->user_email, $subject, $message );
}
elseif( in_array( $userdata->user_role, array( \'editor\', \'administrator\' ) ) && $userdata->user_role != $old_user_data->user_role )
{
// We\'re updating the role of an existing user, make sure they\'re
// becoming an admin or editor, then send the message.
wp_mail( $userdata->user_email, $subject, $message );
}
}
以上内容尚未测试。小心复制和粘贴。只是想让你开始。