找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2397|回复: 0

[分享] WordPress修改新用户注册邮件内容

[复制链接]
发表于 2016-2-3 14:57:14 | 显示全部楼层 |阅读模式 来自 河南省新乡市
今天小V在某wordpress网站注册了个帐号,在完成注册后该网站系统发送来一封默认的注册提醒通知邮件,邮件样式如下图:当时小V就想到wordpress默认的新用户注册提醒邮件的样式也未免太破了吧?正好无聊就琢磨了下wordpress的新用户邮件通知的函数。发现在wp-includes/pluggable.php文件有个wp_new_user_notification()函数是用来定义新用户邮件通知的。小V根据文档琢磨了下发现可以用以下方式来定义邮件样式:
  1. <?php
  2. /*
  3.   Plugin Name: new-user-notification
  4.   Description:重新定义发送邮件的内容和格式
  5.   Version: 1.0
  6. */
  7.    
  8. if ( !function_exists('wp_new_user_notification') ) :
  9. /**
  10. * Notify the blog admin of a new user, normally via email.
  11. *
  12. * @since 2.0
  13. *
  14. * @param int $user_id User ID
  15. * @param string $plaintext_pass Optional. The user's plaintext password
  16. */
  17. function wp_new_user_notification($user_id, $plaintext_pass = '') {
  18.     $user = get_userdata( $user_id );
  19.    
  20.     $user_login = stripslashes($user->user_login);
  21.     $user_email = stripslashes($user->user_email);
  22.    
  23.     // 获取博客名称
  24.     $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
  25.    
  26.     // 给管理员发送的邮件内容,这里是HTML格式
  27.     $message = '<html>
  28.     <head>
  29.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  30.     <title>新用户注册</title>
  31.     </head>
  32.     <body>
  33.     <div align="center">
  34.     <table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;">
  35.     <tr>
  36.     <td style="padding:0;">
  37.     <table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;">
  38.     <tr><td style="line-height:2;font-size:12px;">您的网站 <strong>' . $blogname . '</strong>
  39.     有新用户注册。<br />用户名:' . $user_login . '<br />
  40.     Email:' . $user_email . '<br />
  41.     <br />如果您不是  <strong>' . $blogname . '</strong> 的管理员,请直接忽略本邮件!</div>
  42.     </td></tr></table></td></tr></table></div></body></html>';
  43.    
  44.     // 给网站管理员发送邮件
  45.     $message_headers = "Content-Type: text/html; charset="utf-8"\n";
  46.     @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message, $message_headers);
  47.    
  48.     if ( empty($plaintext_pass) )
  49.         return;
  50.       
  51.     // 你可以在此修改发送给新用户的通知Email,这里是HTML格式
  52.     $message = '<html>
  53.     <head>
  54.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  55.     <title>新用户注册</title>
  56.     </head>
  57.     <body>
  58.     <div align="center">
  59.     <table cellpadding="0" cellspacing="1" style="border:3px solid #d9e9f1;background:#7fbddd; text-align:left;">
  60.     <tr><td style="padding:0;">
  61.     <table cellpadding="30" cellspacing="0" style="border:1px solid #ffffff;background:#f7f7f7;width:500px;">
  62.     <tr>
  63.     <td style="line-height:2;font-size:12px;">您刚刚在网站 <strong>' . $blogname . '</strong> 注册一个帐号。<br />
  64.     用户名:' . $user_login . '<br />登录密码:' . $plaintext_pass . '<br />登录网址:<a href="' . wp_login_url() . '">' . wp_login_url() . '</a><br />
  65.     <br />如果您没有在 <strong>'. $blogname . '</strong> 注册过任何信息,请直接忽略本邮件!</div>
  66.     </td></tr></table></td></tr></table></div>
  67.     </body>
  68.     </html>';
  69.    
  70.     // sprintf(__('[%s] Your username and password'), $blogname) 为邮件标题
  71.     wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers);
  72. }
  73. endif;
  74.    
  75. ?>
复制代码
以上代码的加到主题的functions.php或者命名为piaoxian_new-user.php文件然后把文件传到wp-content/plugins/文件夹下,再到后台启用一个名为piaoxian_new-user-notification的插件即可。

发帖求助前要善用【论坛搜索】功能,那里可能会有你要找的答案;

如何回报帮助你解决问题的坛友,好办法就是点击帖子下方的评分按钮给对方加【金币】不会扣除自己的积分,做一个热心并受欢迎的人!

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则 需要先绑定手机号

关闭

站长推荐上一条 /1 下一条

QQ|侵权投诉|广告报价|手机版|小黑屋|西部数码代理|飘仙建站论坛 ( 豫ICP备2022021143号-1 )

GMT+8, 2024-5-1 23:29 , Processed in 0.057127 second(s), 8 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表