最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Wordpress用户注册邮件内容自定义格式美化实例
时间:2014-11-22 编辑:简简单单 来源:一聚教程网
WordPress提供了一个可供插件重新定义的新用户邮件通知函数 wp_new_user_notification(),现在我们来重新定义这个函数的内容,来美化我们的邮件内容格式。
原函数函数内容如下:
代码如下 | 复制代码 |
if ( !function_exists('wp_new_user_notification') ) : /** * Notify the blog admin of a new user, normally via email. * * @since 2.0 * * @param int $user_id User ID * @param string $plaintext_pass Optional. The user's plaintext password */ function wp_new_user_notification($user_id, $plaintext_pass = '') { $user = get_userdata( $user_id ); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); // The blogname option is escaped with esc_html on the way into the database in sanitize_option // we want to reverse this for the plain text arena of emails. $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); $message = sprintf(__('New user registration on your site %s:'), $blogname) . "rnrn"; $message .= sprintf(__('Username: %s'), $user_login) . "rnrn"; $message .= sprintf(__('E-mail: %s'), $user_email) . "rn"; @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message); if ( empty($plaintext_pass) ) return; $message = sprintf(__('Username: %s'), $user_login) . "rn"; $message .= sprintf(__('Password: %s'), $plaintext_pass) . "rn"; $message .= wp_login_url() . "rn"; wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message); } endif; |
自定义邮件内容和格式
我们可以新建一个"插件",重新定义的wp_new_user_notification函数定义的邮件内容即可。我们在wp-content/plugins/目录下,新建一个文本文件命名为new-user-notification.php,插入以下代码,保存,然后在后台启动插件new-user-notification即可:
代码如下 | 复制代码 | ||||
/* Plugin Name: new-user-notification Description:重新定义发送邮件的内容和格式 Version: 1.0 */ if ( !function_exists('wp_new_user_notification') ) : /** * Notify the blog admin of a new user, normally via email. * * @since 2.0 * * @param int $user_id User ID * @param string $plaintext_pass Optional. The user's plaintext password */ function wp_new_user_notification($user_id, $plaintext_pass = '') { $user = get_userdata( $user_id ); $user_login = stripslashes($user->user_login); $user_email = stripslashes($user->user_email); // 获取博客名称 $blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES); // 给管理员发送的邮件内容,这里是HTML格式 $message = '
// 给网站管理员发送邮件 $message_headers = "Content-Type: text/html; charset="utf-8"n"; @wp_mail(get_option('admin_email'), sprintf(__('[%s] New User Registration'), $blogname), $message, $message_headers); if ( empty($plaintext_pass) ) return; // 你可以在此修改发送给新用户的通知Email,这里是HTML格式 $message = '
// sprintf(__('[%s] Your username and password'), $blogname) 为邮件标题 wp_mail($user_email, sprintf(__('[%s] Your username and password'), $blogname), $message, $message_headers); } endif; ?> |
相关文章
- HTML简单购物数量小程序代码展示 10-31
- html canvas实现弹幕功能 10-31
- HTML中空格表示的意义 10-31
- html area标签解读 10-31
- html使用表单标签实现注册页面代码展示 10-31
- 使用HTML截图并保存为本地图片的代码展示 10-31