wordpress用户账户信息更新、重置密码或账户被删除时发送提示邮
不知道大家发现没有,很多知名网站在用户账户密码被修改的时候都会发送一封提醒邮件,来防止网站用户的密码被恶意修改。本来wordpress是属于博客程序,但是最近越来越多的wordpress网站开放了会员中心系统,那么这样一来就不得不考虑到用户的账户安全了,所以做一个密码修改提示邮件的功能就非常有必要了,小V下面给出具体代码(PS:代码都是加到functions.php文件即可):
function password_reset_mail( KaTeX parse error: Expected '}', got 'EOF' at end of input: …id ) { site_name = get_bloginfo(‘name’);
s
i
t
e
u
r
l
=
g
e
t
b
l
o
g
i
n
f
o
(
′
w
p
u
r
l
′
)
;
site_url = get_bloginfo('wpurl');
siteurl =getbloginfo(′wpurl′); user_info = get_userdata(
u
s
e
r
i
d
)
;
user_id );
userid ); to =
u
s
e
r
i
n
f
o
−
>
u
s
e
r
e
m
a
i
l
;
user_info->user_email;
userinfo−>useremail; subject = “密码修改提示:”.
s
i
t
e
n
a
m
e
.
"
"
;
site_name."";
sitename.""; message = “您好,” .KaTeX parse error: Undefined control sequence: \n at position 28: …isplay_name . "\̲n̲您在".site_name.“的账户密码已被修改!\n\n如果不是您本人修改的,请迅速至”.
s
i
t
e
u
r
l
.
"
确
认
。
"
;
w
p
m
a
i
l
(
site_url."确认。"; wp_mail(
siteurl."确认。"; wpmail( to,
s
u
b
j
e
c
t
,
subject,
subject, message);
}
add_action( ‘password_reset’, ‘password_reset_mail’, 10, 2);
此段代码是参考以下代码做出修改而得来的:
function user_profile_update( KaTeX parse error: Expected '}', got 'EOF' at end of input: …id ) { site_url = get_bloginfo(‘wpurl’);
u
s
e
r
i
n
f
o
=
g
e
t
u
s
e
r
d
a
t
a
(
user_info = get_userdata(
userinfo =getuserdata( user_id );
t
o
=
to =
to = user_info->user_email;
s
u
b
j
e
c
t
=
"
P
r
o
f
i
l
e
U
p
d
a
t
e
d
:
"
.
subject = "Profile Updated: ".
subject = "ProfileUpdated:".site_url."";
m
e
s
s
a
g
e
=
"
H
e
l
l
o
"
.
message = "Hello " .
message = "Hello" .user_info->display_name . "\nYour profile has been updated!\n\nThank you for visiting\n ".
s
i
t
e
u
r
l
.
"
"
;
w
p
m
a
i
l
(
site_url.""; wp_mail(
siteurl.""; wpmail( to,
s
u
b
j
e
c
t
,
subject,
subject, message);
}
add_action( ‘profile_update’, ‘user_profile_update’, 10, 2);
第二段代码的作用是在用户更新账户信息时发出邮件提示,代码来源:
再来一段,当wordpress用户的帐号被删除时给用户发送提示邮件的代码:
function v7v3_delete_user( KaTeX parse error: Expected '}', got 'EOF' at end of input: …_id ) { global wpdb;
$site_name = get_bloginfo(‘name’);
u
s
e
r
o
b
j
=
g
e
t
u
s
e
r
d
a
t
a
(
user_obj = get_userdata(
userobj =getuserdata( user_id );
e
m
a
i
l
=
email =
email = user_obj->user_email;
s
u
b
j
e
c
t
=
"
帐
号
删
除
提
示
:
"
.
subject = "帐号删除提示:".
subject = "帐号删除提示:".site_name."";
m
e
s
s
a
g
e
=
"
您
好
,
"
.
message = "您好," .
message = "您好," .user_obj->display_name . “\n您在”.KaTeX parse error: Undefined control sequence: \n at position 23: …me."的账户已被管理员删除!\̲n̲\n如果您对本次操作有什么异议…email,
s
u
b
j
e
c
t
,
subject,
subject, message);
}
add_action( ‘delete_user’, ‘v7v3_delete_user’ );
PS:有很长一段时间小V都没有怎么更新网站了,从今天起小V又开始努力的更新网站了~~欢迎大家来访。
本文由大资源网整理发布,转载请说明出处:https://www.dzy10.com/52443.html 免费领取VIP送建站课