子比主题 – 用户登陆邮件提醒功能
给自己的子比主题加一个用户登陆邮件提醒功能,这款功能子比主题没有的,所以func代码即可解决这个问题,用户登录之后就会有提醒,包括管理员也有的,喜欢的自行部署吧!代码部署
定位:/wp-content/themes/zibll/func.php文件,没有这个文件自己创建一个,记得加上php头,要不然会报错,将代码加里面即可!
/**
* 用户登陆邮件提醒
*/
function notify_all_user_login($user_login, $user) {
date_default_timezone_set('PRC');
$user_email = $user->user_email;
$subject = '您的账户登录提醒 - ' . get_option("blogname");
$message = '<p>您好!您的账户(' . $user_login . ')已成功登录:</p>' .
"<p>登录时间:" . date("Y-m-d H:i:s") . "</p>" .
"<p>登录IP:" . $_SERVER['REMOTE_ADDR'] . "</p>" .
"<p>设备信息:" . $_SERVER['HTTP_USER_AGENT'] . "</p>";
$domain = preg_replace('#^www\.#', '', strtolower($_SERVER['SERVER_NAME']));
$headers = array(
'Content-Type: text/html; charset=' . get_option('blog_charset'),
'From: 系统通知 <no-reply@' . $domain . '>'
);
wp_mail($user_email, $subject, $message, $headers);
}
add_action('wp_login', 'notify_all_user_login', 10, 2);
页:
[1]