wpDiscuz 7 Beta Version is Released!

 

Today, on 01.20.2020 we’re excited to release wpDiscuz 7 Beta 1 into the wild!
The version 7 has been in development since December 2018. About one year of hard work is ready to be tested. It’s hard to believe it’s been so long since our last major v5 release, but sometimes good things are worth waiting for.

Try wpDiscuz 7 Beta 1

Comment approved notification - don't send for comments on custom post type  

  RSS

Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
13/09/2019 3:12 pm  

I have the comment approved email notification set up and working using wpDiscuz.

I am now using a plugin (GeoDirectory) which uses custom post types and has its own system for displaying comments and sending comment notifications.

When a comment on this CPT is approved, both wpDiscuz and GeoDirectory send an email notification, which I do not want to happen.

Is there a way (a filter maybe?) to stop wpDiscuz sending the comment approved email for comments on a custom post type? I still want wpDiscuz to send the comment approved email for comments on ordinary posts.


Quote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 3513
13/09/2019 4:57 pm  

Hi@salubritas,

Please follow the steps below:

1. Open the wp-content/plugins/wpdiscuz/utils/class.WpdiscuzHelperEmail.php file

2. Find notifyOnApproving function

3. replace with the following one:

public function notifyOnApproving($comment) {
       $wpdiscuz = wpDiscuz();
       if ($comment && $wpdiscuz->helper->isLoadWpdiscuz(get_post($comment->comment_post_ID))) {
           $user = $comment->user_id ? get_userdata($comment->user_id) : null;
           if ($user) {
               $email = $user->user_email;
           } else {
               $email = $comment->comment_author_email;
           }           $subject = $this->optionsSerialized->phrases['wc_comment_approved_email_subject'];
           $message = $this->optionsSerialized->phrases['wc_comment_approved_email_message'];
           $siteUrl = get_site_url();
           $blogTitle = get_option('blogname');
           $postTitle = get_the_title($comment->comment_post_ID);
           if (strpos($message, '[SITE_URL]') !== false) {
               $message = str_replace('[SITE_URL]', $siteUrl, $message);
           }
           if (strpos($message, '[POST_URL]') !== false) {
               $postPermalink = get_permalink($comment->comment_post_ID);
               $message = str_replace('[POST_URL]', $postPermalink, $message);
           }
           if (strpos($message, '[BLOG_TITLE]') !== false) {
               $message = str_replace('[BLOG_TITLE]', $blogTitle, $message);
           }
           if (strpos($message, '[POST_TITLE]') !== false) {
               $message = str_replace('[POST_TITLE]', $postTitle, $message);
           }
           if (strpos($message, '[COMMENT_URL]') !== false) {
               $commentPermalink = get_comment_link($comment->comment_ID);
               $message = str_replace('[COMMENT_URL]', $commentPermalink, $message);
           }
           if (strpos($message, '[COMMENT_AUTHOR]') !== false) {
               $message = str_replace('[COMMENT_AUTHOR]', $comment->comment_author, $message);
           }
           if (strpos($message, '[COMMENT_CONTENT]') !== false) {
               $message = str_replace('[COMMENT_CONTENT]', $comment->comment_content, $message);
           }
           if (strpos($subject, '[BLOG_TITLE]') !== false) {
               $subject = str_replace('[BLOG_TITLE]', $blogTitle, $subject);
           }
           if (strpos($subject, '[POST_TITLE]') !== false) {
               $subject = str_replace('[POST_TITLE]', $postTitle, $subject);
           }
           $headers = array();
           $mailContentType = apply_filters('wp_mail_content_type', 'text/html');
           $fromName = apply_filters('wp_mail_from_name', $blogTitle);
           $fromName = html_entity_decode($fromName, ENT_QUOTES);
           $parsedUrl = parse_url($siteUrl);
           $domain = isset($parsedUrl['host']) ? WpdiscuzHelper::fixEmailFrom($parsedUrl['host']) : '';
           $fromEmail = 'no-reply@' . $domain;
           $fromEmail = apply_filters('wp_mail_from', $fromEmail);
           $headers[] = "Content-Type:  $mailContentType; 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);
       }
   }

ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
13/09/2019 7:19 pm  

Thank you, that worked.

Is there any chance of a future change so it can be done with a filter, or a check for a replacement class file in the theme (like you have done for WpdiscuzWalker)? Or any method other than changing the plugin code directly.


ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
13/09/2019 7:25 pm  

Or is this change going to make it into the plugin anyway?

I'm not sure what isLoadWpdiscuz does but it sounds like a neat solution if it checks for wpDiscuz being used on that particular post.


ReplyQuote
Astghik
(@astghik)
Support Team Admin
Joined: 2 years ago
Posts: 3513
14/09/2019 4:51 pm  
Posted by: @salubritas

Or is this change going to make it into the plugin anyway?

yes, we're going to add these changes in the plugin core. 


ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
28/10/2019 9:43 pm  

Sorry for the late response but I've just noticed that this isn't working as expected.

It has actually stopped the comment approved notification being sent for all post types.

I tried to track down the problem and I think it is because isLoadWpdiscuz checks for is_singular().

Because comment approval happens in admin there is no post currently being viewed and is_singular() will always return false, if I understand it correctly.

I have reverted the change. As a workaround I have set the priority of the other plugin's transition_comment_status filter ahead of wpDiscuz, then got it to remove_all_actions from that filter when it is called to prevent the doubling up of emails.

It works, but not a very nice solution.


Astghik liked
ReplyQuote
Elvina
(@elvina)
Reputable Member Moderator
Joined: 5 months ago
Posts: 413
29/10/2019 2:01 pm  

Hi @salubritas,

Please replace the code provided by Astghik with the following one:

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]"], [$blogTitle, $postTitle], $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);
}
}
}
This post was modified 3 months ago by Elvina

ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
29/10/2019 2:22 pm  

I tried that and now get these errors logged on approving a comment:

[29-Oct-2019 10:17:33 UTC] PHP Notice: Undefined property: WpdiscuzHelperEmail::$options in ..\wp-content\plugins\wpdiscuz\utils\class.WpdiscuzHelperEmail.php on line 346
[29-Oct-2019 10:17:33 UTC] PHP Notice: Trying to get property of non-object in ..\wp-content\plugins\wpdiscuz\utils\class.WpdiscuzHelperEmail.php on line 346
[29-Oct-2019 10:17:33 UTC] PHP Notice: Undefined property: WpdiscuzHelperEmail::$options in ..\wp-content\plugins\wpdiscuz\utils\class.WpdiscuzHelperEmail.php on line 347
[29-Oct-2019 10:17:33 UTC] PHP Notice: Trying to get property of non-object in ..\wp-content\plugins\wpdiscuz\utils\class.WpdiscuzHelperEmail.php on line 347

I'm guessing it is dependent on changes made elsewhere in the class.


ReplyQuote
Elvina
(@elvina)
Reputable Member Moderator
Joined: 5 months ago
Posts: 413
29/10/2019 3:27 pm  

@salubritas,

Please try this code:

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;
               } $subject = $this->optionsSerialized->phrases['wc_comment_approved_email_subject'];
               $message = $this->optionsSerialized->phrases['wc_comment_approved_email_message'];
               $siteUrl = get_site_url();
               $blogTitle = get_option('blogname');
               $postTitle = get_the_title($comment->comment_post_ID);
               if (strpos($message, '[SITE_URL]') !== false) {
                   $message = str_replace('[SITE_URL]', $siteUrl, $message);
               }
               if (strpos($message, '[POST_URL]') !== false) {
                   $postPermalink = get_permalink($comment->comment_post_ID);
                   $message = str_replace('[POST_URL]', $postPermalink, $message);
               }
               if (strpos($message, '[BLOG_TITLE]') !== false) {
                   $message = str_replace('[BLOG_TITLE]', $blogTitle, $message);
               }
               if (strpos($message, '[POST_TITLE]') !== false) {
                   $message = str_replace('[POST_TITLE]', $postTitle, $message);
               }
               if (strpos($message, '[COMMENT_URL]') !== false) {
                   $commentPermalink = get_comment_link($comment->comment_ID);
                   $message = str_replace('[COMMENT_URL]', $commentPermalink, $message);
               }
               if (strpos($message, '[COMMENT_AUTHOR]') !== false) {
                   $message = str_replace('[COMMENT_AUTHOR]', $comment->comment_author, $message);
               }
               if (strpos($message, '[COMMENT_CONTENT]') !== false) {
                   $message = str_replace('[COMMENT_CONTENT]', $comment->comment_content, $message);
               }
               if (strpos($subject, '[BLOG_TITLE]') !== false) {
                   $subject = str_replace('[BLOG_TITLE]', $blogTitle, $subject);
               }
               if (strpos($subject, '[POST_TITLE]') !== false) {
                   $subject = str_replace('[POST_TITLE]', $postTitle, $subject);
               }
               $headers = array();
               $mailContentType = apply_filters('wp_mail_content_type', 'text/html');
               $fromName = apply_filters('wp_mail_from_name', $blogTitle);
               $fromName = html_entity_decode($fromName, ENT_QUOTES);
               $parsedUrl = parse_url($siteUrl);
               $domain = isset($parsedUrl['host']) ? WpdiscuzHelper::fixEmailFrom($parsedUrl['host']) : '';
               $fromEmail = 'no-reply@' . $domain;
               $fromEmail = apply_filters('wp_mail_from', $fromEmail);
               $headers[] = "Content-Type:  $mailContentType; 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);
           }
       }
   }

 


ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
31/10/2019 6:00 pm  

Thanks. I see you put an update out yesterday and I assume this is included?

When I get some time I will install the update on my dev environment and retest this.


ReplyQuote
Elvina
(@elvina)
Reputable Member Moderator
Joined: 5 months ago
Posts: 413
01/11/2019 2:52 pm  

@salubritas,

I'm sorry, it hasn't been included in the latest update.

However, the code will be added in the next version for sure.


ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
01/11/2019 3:04 pm  

Oh OK.... it looks like you have another update out through now - 5.3.4.

Which version is the fix above for? 5.3.2? I'm guessing there are code changes in 5.3.3 which is why you provided a different version before. I see "Code Optimization" in the changelog for 5.3.3.

Is this fix in 5.3.4? I don't see it in the changelog.

I don't want to apply the fix and then have the update overwrite it.

I'm thinking the best thing is to wait for the update which includes this, seeing as I have my own workaround for it now. Will it be clear when this is fixed in the changelog visible in WP Admin? Or is that just a summary?


ReplyQuote
Elvina
(@elvina)
Reputable Member Moderator
Joined: 5 months ago
Posts: 413
01/11/2019 3:55 pm  

@salubritas,

Please don't worry about this.

Changes will be included in the next version update.

Will it be clear when this is fixed in the changelog visible in WP Admin? Or is that just a summary?

Sure, it will added to the changelog.


ReplyQuote
Salubritas
(@salubritas)
Active Member
Joined: 7 months ago
Posts: 15
01/11/2019 4:27 pm  

OK thanks. I'll look out for the next update and check the changelog.


ReplyQuote
Share:
Green
Default
Pear
Black Emo
{green}:grinning:
{green}:wink:
{green}:face:
{green}:inlove:
{green}:sweaty:
{green}:surprised:
{green}:lovekiss:
{green}:laugh:
{green}:formalsmile:
{green}:displeased:
{green}:cool:
{green}:resent:
{green}:nerd:
{green}:screaming:
{green}:amazed:
{green}:sad:
{green}:deceitful:
{green}:starryeyes:
{green}:evil:
{green}:shocked:
{green}:tears:
{green}:sulky:
{green}:smile:
{green}:vomited:
{green}:hi:
{green}:afraid:
{green}:crazy:
{green}:rabid:
{green}:fighting:
{green}:nonoise:
{green}:blushed:
{green}:idontknow:
{green}:scared:
{green}:razz:
{green}:kiss:
{green}:eat:
{green}:shutmouth:
{green}:gape:
{green}:suspicious:
{green}:laughingoutloud:
{green}:bruise:
{green}:crying:
{green}:pray:
{green}:serious:
{green}:excitement:
:)
:d
:wink:
:mrgreen:
:neutral:
:twisted:
:arrow:
:shock:
:???:
:cool:
:evil:
:oops:
:razz:
:roll:
:cry:
:eek:
:lol:
:mad:
:sad:
:!:
:?:
:idea:
:hmm:
:beg:
:whew:
:chuckle:
:silly:
:envy:
:shutmouth:
{pear}:happy:
{pear}:smile:
{pear}:laugh:
{pear}:laughingoutloud:
{pear}:crying:
{pear}:exhausted:
{pear}:nerd:
{pear}:surprised:
{pear}:veryhungry:
{pear}:wink:
{blackemo}:laughtertotears:
{blackemo}:gift:
{blackemo}:love:
{blackemo}:inlove:
{blackemo}:shamefaced:
{blackemo}:heart:
{blackemo}:crazy:
{blackemo}:anguished:
{blackemo}:bruise:
{blackemo}:easymoney:
{blackemo}:exhausted:
{blackemo}:vampire:
{blackemo}:shutmouth:
{blackemo}:wink:
{blackemo}:carnival:
{blackemo}:flowers:
{blackemo}:hotdrink:
{blackemo}:party: