Dec 17, 2020 8:01 pm
Hi Forum!
we’ve recently switched to wpdiscuz for the private comments feature (it’s a very neat feature for those considering buying it!)
Is it possible to send a notification email to the post owner once a comment has been approved? Comments are not moderated by the post author so we need to notify them of new comments (once approved)
5 Replies
Dec 17, 2020 11:07 pm
I'm happy to amend this section in class.WpdiscuzHelperEmail.php since I currently don't need to notify the comment author, although this would be a great feature request if we can get it working!
public function notifyOnApproving($comment) {
if ($comment) {
$wpdiscuz = wpDiscuz();
$isLoadWpdiscuz = false;
$post = get_post($comment->comment_post_ID);
if ($post && is_object($post)) {
$form = $wpdiscuz->wpdiscuzForm->getForm($post->ID);
$isLoadWpdiscuz = $form->getFormID() && (comments_open($post) || $post->comment_count) && post_type_supports($post->post_type, "comments");
}
if ($isLoadWpdiscuz) {
$user = $comment->user_id ? get_userdata($comment->user_id) : null;
if ($user) {
$email = $user->user_email;
} else {
$email = $comment->comment_author_email;
}
$siteUrl = get_site_url();
$blogTitle = get_option("blogname");
$postTitle = get_the_title($comment->comment_post_ID);
$search = ["[SITE_URL]", "[POST_URL]", "[BLOG_TITLE]", "[POST_TITLE]", "[COMMENT_URL]", "[COMMENT_AUTHOR]", "[COMMENT_CONTENT]"];
$replace = [$siteUrl, get_permalink($comment->comment_post_ID), $blogTitle, $postTitle, get_comment_link($comment->comment_ID), $comment->comment_author, wpautop($comment->comment_content)];
$message = str_replace($search, $replace, $this->options->phrases["wc_comment_approved_email_message"]);
$subject = str_replace(["[BLOG_TITLE]", "[POST_TITLE]", "[COMMENT_AUTHOR]"], [$blogTitle, $postTitle, $comment->comment_author], $this->options->phrases["wc_comment_approved_email_subject"]);
$headers = [];
$fromName = html_entity_decode($blogTitle, ENT_QUOTES);
$parsedUrl = parse_url($siteUrl);
$domain = isset($parsedUrl["host"]) ? WpdiscuzHelper::fixEmailFrom($parsedUrl["host"]) : "";
$fromEmail = "no-reply@" . $domain;
$headers[] = "Content-Type: text/html; charset=UTF-8";
$headers[] = "From: " . $fromName . " <" . $fromEmail . "> \r\n";
$subject = html_entity_decode($subject, ENT_QUOTES);
$message = html_entity_decode($message, ENT_QUOTES);
wp_mail($email, $subject, do_shortcode($message), $headers);
}
}
}