argon-theme icon indicating copy to clipboard operation
argon-theme copied to clipboard

评论回复邮件增加原评论显示;增加评论审核通过邮件

Open totoropcbeta opened this issue 5 years ago • 0 comments

代码位置:第1096行

// 发送评论审核通过邮件

add_action('comment_unapproved_to_approved', 'loper_comment_approved');
function loper_comment_approved($comment) {
    if (get_option("argon_comment_allow_mailnotice") != "true"){
		return;
	}
	$id = $comment -> comment_ID;
    if (get_comment_meta($id, "enable_mailnotice", true) == "true"){
        if(is_email($comment->comment_author_email)) {
            $id = $comment -> comment_ID;
        	$commentPostID = $comment -> comment_post_ID;
            // 邮件标题,可自行更改
        	$title = __("您在", 'argon') . " [" . get_option('blogname') . "] 的文章" . "《" . get_post_title_by_id($commentPostID) . "》" . __("的评论已通过审核", 'argon');
        	$fullTitle = __("您在", 'argon') . " [" . get_option('blogname') . "] 的文章" . "《" . get_post_title_by_id($commentPostID) . "》" . __("的评论已通过审核", 'argon');
        	$link = get_permalink($commentPostID) . "#comment-" . $id;
        	$html = "<div style='background: #fff;box-shadow: 0 15px 35px rgba(50,50,93,.1), 0 5px 15px rgba(0,0,0,.07);border-radius: 6px;margin: 15px auto 50px auto;padding: 35px 30px;max-width: min(calc(100% - 100px), 1200px);'>
        			<div style='font-size:30px;text-align:center;margin-bottom:15px;'>" . htmlspecialchars($fullTitle)  ."</div>
        			<div style='background: rgba(0, 0, 0, .15);height: 1px;width: 300px;margin: auto;margin-bottom: 35px;'></div>
        			<div style='font-size: 18px;border-left: 4px solid rgba(0, 0, 0, .15);width: max-content;width: -moz-max-content;margin: auto;padding: 20px 30px;background: rgba(0,0,0,.08);border-radius: 6px;box-shadow: 0 2px 4px rgba(0,0,0,.075)!important;min-width: 60%;max-width: 90%;margin-bottom: 60px;'>
        				<div style='margin-bottom: 10px;'><strong><span style='color: black;'>这是您的评论:</span></strong></div>
        				" . str_replace("\n", "<div></div>", trim(get_comment($comment)->comment_content)) . " 
        			</div>
        			<div style='width: max-content;width: --moz-max-content;margin: auto;margin-bottom:50px;'>
        				<a href='" . $link . "' style='color: #fff;background-color: #5e72e4;border-color: #5e72e4;box-shadow: 0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08);padding: 15px 25px;font-size: 18px;border-radius: 4px;text-decoration: none;'>" . __("前往查看", 'argon') . "</a>
        			</div>
        		</div>";
            @wp_mail($comment->comment_author_email, $title, $html, "Content-Type: text/html; charset=UTF-8");
        }        
    }
}



//发送评论通知邮件
function comment_mail_notify($comment){
	if (get_option("argon_comment_allow_mailnotice") != "true"){
		return;
	}
	if ($comment == null){
		return;
	}
	$id = $comment -> comment_ID;
	$commentPostID = $comment -> comment_post_ID;
	$commentAuthor = $comment -> comment_author;
	$parentID = $comment -> comment_parent;
	if ($parentID == 0){
		return;
	}
	$parentComment = get_comment($parentID);
	$parentEmail =  $parentComment -> comment_author_email;
	if (get_comment_meta($parentID, "enable_mailnotice", true) == "true"){
		if (check_email_address($parentEmail)){
			$title = __("您在", 'argon') . " [" . get_option('blogname') . "] 的文章" . "《" . get_post_title_by_id($commentPostID) . "》" . __("的评论有了新的回复", 'argon');
			$fullTitle = __("您在", 'argon') . " [" . get_option('blogname') . "] 的文章" . "《" . get_post_title_by_id($commentPostID) . "》" . __("的评论有了新的回复", 'argon');
			$content = htmlspecialchars(get_comment_meta($id, "comment_content_source", true));
			$link = get_permalink($commentPostID) . "#comment-" . $id;
			$unsubscribeLink = site_url("unsubscribe-comment-mailnotice?comment=" . $parentID . "&token=" . get_comment_meta($parentID, "mailnotice_unsubscribe_key", true));
			$html = "<div style='background: #fff;box-shadow: 0 15px 35px rgba(50,50,93,.1), 0 5px 15px rgba(0,0,0,.07);border-radius: 6px;margin: 15px auto 50px auto;padding: 35px 30px;max-width: min(calc(100% - 100px), 1200px);'>
					<div style='font-size:30px;text-align:center;margin-bottom:15px;'>" . htmlspecialchars($fullTitle)  ."</div>
					<div style='background: rgba(0, 0, 0, .15);height: 1px;width: 300px;margin: auto;margin-bottom: 35px;'></div>
					<div style='font-size: 18px;border-left: 4px solid rgba(0, 0, 0, .15);width: max-content;width: -moz-max-content;margin: auto;padding: 20px 30px;background: rgba(0,0,0,.08);border-radius: 6px;box-shadow: 0 2px 4px rgba(0,0,0,.075)!important;min-width: 60%;max-width: 90%;margin-bottom: 60px;'>
						<div style='margin-bottom: 10px;'><strong><span style='color: black;'>这是您的评论:</span></strong></div>
						" . str_replace("\n", "<div></div>", trim(get_comment($parentID)->comment_content)) . " 
					</div>
					<div style='font-size: 18px;border-left: 4px solid rgba(0, 0, 0, .15);width: max-content;width: -moz-max-content;margin: auto;padding: 20px 30px;background: rgba(0,0,0,.08);border-radius: 6px;box-shadow: 0 2px 4px rgba(0,0,0,.075)!important;min-width: 60%;max-width: 90%;margin-bottom: 60px;'>
						<div style='margin-bottom: 10px;'><strong><span style='color: #5e72e4;'>@" . htmlspecialchars($commentAuthor) . "</span> " . __("回复了你", 'argon') . ":</strong></div>
						" . str_replace("\n", "<div></div>", $content) . " 
					</div>
					<div style='width: max-content;width: --moz-max-content;margin: auto;margin-bottom:50px;'>
						<a href='" . $link . "' style='color: #fff;background-color: #5e72e4;border-color: #5e72e4;box-shadow: 0 4px 6px rgba(50,50,93,.11), 0 1px 3px rgba(0,0,0,.08);padding: 15px 25px;font-size: 18px;border-radius: 4px;text-decoration: none;'>" . __("前往查看", 'argon') . "</a>
					</div>
					<div style='width: max-content;width: --moz-max-content;margin: auto;margin-bottom:30px;'>
						<a href='" . $unsubscribeLink . "' style='color: #5e72e4;font-size: 16px;text-decoration: none;'>" . __("退订该评论的邮件提醒", 'argon') . "</a>
					</div>
				</div>";
			send_mail($parentEmail, $title, $html);
		}
	}
}

参考代码出处:繁夜

totoropcbeta avatar Dec 16 '20 14:12 totoropcbeta