百度
360搜索
搜狗搜索

子比主题未登录用户评论后回复,收不到邮件问题解决方法详细介绍

子比主题使用整体感觉还算不错,但是例如未登录用户评论后却收不到回复邮件、评论框网址、点击用户名跳转,曾经希望作者能够将这些功能集成到主题中免得我自己修改麻烦,但是反馈之后被否了,可能这些功能是作者故意去掉的,使其更加契合资源站的定位。

解决方法

子比主题自带的评论审核样式还算可以,为了保持一致性就决定两者结合,把原来邮件的语序重新调整并使用上边可用的函数对评论者姓名、评论内容、评论时间、回复等信息进行调用,得到了如下代码:

//访客评论邮件回复
add_action
(
'comment_post'
,
'comment_mail_notify'
,
99
)
;
add_action
(
'comment_unapproved_to_approved'
,
'comment_mail_notify'
,
99
)
;
function
comment_mail_notify
(
$comment_id
)
{
$comment =
get_comment
(
$comment_id
)
;
if
(
$comment-
>
comment_approved !=
'1'
)
return
;//如果评论未通过审核,return
$admin_email =
get_bloginfo
(
'admin_email'
)
;
// $admin_email 可改为你指定的 e-mail.
$comment_author_email =
trim
(
$comment-
>
comment_author_email
)
;
$parent_id = $comment-
>
comment_parent ? $comment-
>
comment_parent
:
''
;
$to = $parent_id ?
trim
(
get_comment
(
$parent_id
)
-
>
comment_author_email
)
:
''
;
$spam_confirmed = $comment-
>
comment_approved;
if
((
$parent_id !=
''
)
&&
(
$spam_confirmed !=
'spam'
)
&&
(
$to != $admin_email
))
{
/* 上面的if判断是决定是否发出邮件的关键:
($parent_id != '') && ($spam_confirmed != 'spam'): 评论是被回复的, 而且不是 spam 才可以发(必需!!)
($to != $admin_email) : 不给 admin发邮件(可选).
($comment_author_email == $admin_email) : 只有 admin 的回复才发邮件(可选).
可根据个人需要修改上面的条件.
*/
$wp_email =
'no-reply@'
.
preg_replace
(
'#^www\.#'
,
''
,
strtolower
(
$_SERVER
[
'SERVER_NAME'
]))
;//发件人 e-mail 地址,no-reply 可改为可用的 e-mail
$to =
trim
(
get_comment
(
$parent_id
)
-
>
comment_author_email
)
;
$subject =
'您在 ['
.
get_option
(
"blogname"
)
.
'] 的留言有了新的回复'
;//邮件主题
$message =
'您好!'
.
trim
(
get_comment
(
$parent_id
)
-
>
comment_author
)
.
','
;//邮件内容
$message .=
'您于'
.
trim
(
get_comment
(
$parent_id
)
-
>
comment_date
)
.
' '
;
$message .=
'在《'
.
get_the_title
(
$comment-
>
comment_post_ID
)
.
'》中发表评论:'
.
'</br>'
;
$message .=
'<div style="padding: 10px 15px; border-radius: 8px; background: rgba(141, 141, 141, 0.05); line-height: 1.7;">'
.
nl2br
(
get_comment
(
$parent_id
)
-
>
comment_content
)
.
'</div>'
;
$message .=
'</br>'
;
$message .=
''
.
trim
(
$comment-
>
comment_author
)
.
''
;
$message .=
' 于'
.
trim
(
$comment-
>
comment_date
)
.
' 给您的回复如下:</br>'
;
$message .=
'<div style="padding: 10px 15px; border-radius: 8px; background: rgba(141, 141, 141, 0.05); line-height: 1.7;">'
.
nl2br
(
$comment-
>
comment_content
)
.
'</div>'
;
$message .=
'</br>'
;
$message .=
'您可以点击下方按钮查看回复内容</br>'
;
$message .=
'<a target="_blank" style="margin-top: 20px;padding:5px 20px" class="but jb-blue" href="'
.
htmlspecialchars
(
get_comment_link
(
$parent_id
))
.
'">查看回复</a>'
.
"</br>"
;
$from =
"From: \""
.
get_option
(
'blogname'
)
.
"\" <$wp_email>"
;
$headers =
"$from\nContent-Type: text/html; charset="
.
get_option
(
'blog_charset'
)
.
"\n"
;
//wp_mail发送邮件
wp_mail
(
$to, $subject, $message, $headers
)
;
}
}

将此代码放在主题根目录的functions.php即可,为了不产生多余的邮件主题设置里边的发送邮件被我全部关闭了,经过测试目前这种方案能够覆盖所有评论场景,很完美,最终效果图如下。

修改后效果

最后的2个小功能下一篇文章再讲吧!!!

,

网站数据信息

"子比主题未登录用户评论后回复,收不到邮件问题解决方法"浏览人数已经达到46次,如你需要查询该站的相关权重信息,可以点击进入"Chinaz数据" 查询。更多网站价值评估因素如:子比主题未登录用户评论后回复,收不到邮件问题解决方法的访问速度、搜索引擎收录以及索引量、用户体验等。 要评估一个站的价值,最主要还是需要根据您自身的需求,如网站IP、PV、跳出率等!