wpDiscuz - WordPress Comment Plugin
Share:
Notifications
Clear all

Post Author Notification


ljcn
Posts: 11
 ljcn
Topic starter
(@ljcn)
Active Member
Joined: 10 months ago

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
ljcn
Posts: 11
 ljcn
Topic starter
(@ljcn)
Active Member
Joined: 10 months ago

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);
           }
       }
    }

 

Reply
4 Replies
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 3567

@ljcn,

You can use the Email me whenever > Anyone posts a comment WordPress option. It allows authors to receive notification that comments have been made, or comments are held for moderation.  More info here:  https://wpdiscuz.com/docs/wpdiscuz-7/wordpress-settings/comment-subscription/

Reply
ljcn
 ljcn
(@ljcn)
Joined: 10 months ago

Active Member
Posts: 11

@asti thank you, this emails the post author as soon as the comment is submitted. I need it to send the post author an email only after the comment has been approved via moderation (the same way it does for the comment author)

Reply
Asti
 Asti
Support
(@asti)
Joined: 4 years ago

Support member
Posts: 3567

@ljcn,

You may ask the post authors to subscribe to the current post. 

Reply
ljcn
 ljcn
(@ljcn)
Joined: 10 months ago

Active Member
Posts: 11

@asti I'm afraid that's not ideal either (our use case is complicated). 

I need to use the notifyonApproving function above - but to send the email to the post author instead of the comment author. Does your code allow custom files to be rendered from the child theme?

I've tried changing $email = $user->user_email; to $email = $post->the_author_email; but I'm missing something.

Could you help or develop this feature? This function worked with our previous plugin (geodirectory), but prefer the wpdiscuz features (private comments especially) so would rather keep using wpdiscuz. 

Reply
Share: