Created
February 20, 2018 16:29
-
-
Save BrianHenryIE/fba15efb60fe93ad51d7c120f7f41b6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/utils/class.WpdiscuzEmailHelper.php b/utils/class.WpdiscuzEmailHelper.php | |
index c11833c..5cc8da1 100644 | |
--- a/utils/class.WpdiscuzEmailHelper.php | |
+++ b/utils/class.WpdiscuzEmailHelper.php | |
@@ -7,6 +7,10 @@ if (!defined('ABSPATH')) { | |
class WpdiscuzEmailHelper { | |
private $optionsSerialized; | |
+ | |
+ /** | |
+ * @var WpdiscuzDBManager | |
+ */ | |
private $dbManager; | |
public function __construct($optionsSerialized, $dbManager) { | |
@@ -132,42 +136,72 @@ class WpdiscuzEmailHelper { | |
wp_die(); | |
} | |
- /** | |
- * notify on new comments | |
- */ | |
+ /** | |
+ * Send notifications for new comments on the post (excluding replies) | |
+ * | |
+ * @param $post_id int | |
+ * @param $comment_id int | |
+ * @param $email string | |
+ */ | |
public function notifyPostSubscribers($post_id, $comment_id, $email) { | |
$emails_array = $this->dbManager->getPostNewCommentNotification($post_id, $email); | |
$subject = ($this->optionsSerialized->phrases['wc_email_subject']) ? $this->optionsSerialized->phrases['wc_email_subject'] : 'New Comment'; | |
$message = ($this->optionsSerialized->phrases['wc_email_message']) ? $this->optionsSerialized->phrases['wc_email_message'] : 'New comment on the discussion section you\'ve been interested in'; | |
foreach ($emails_array as $e_row) { | |
$this->emailSender($e_row, $comment_id, $subject, $message); | |
+ $subscriber_wp_user_id = $e_row['id']; | |
+ $subscriber_email = $e_row['email']; | |
+ do_action( 'wpdiscoz_notifyPostSubscribers', $post_id, $comment_id, $subscriber_wp_user_id, $subscriber_email ); | |
} | |
} | |
- /** | |
- * notify on comment new replies | |
- */ | |
+ /** | |
+ * Send notifications for new comments on the post (including replies) | |
+ * | |
+ * @param $post_id int | |
+ * @param $comment_id int | |
+ * @param $email string | |
+ */ | |
public function notifyAllCommentSubscribers($post_id, $new_comment_id, $email) { | |
$emails_array = $this->dbManager->getAllNewCommentNotification($post_id, $email); | |
$subject = ($this->optionsSerialized->phrases['wc_new_reply_email_subject']) ? $this->optionsSerialized->phrases['wc_new_reply_email_subject'] : 'New Reply'; | |
$message = ($this->optionsSerialized->phrases['wc_new_reply_email_message']) ? $this->optionsSerialized->phrases['wc_new_reply_email_message'] : 'New reply on the discussion section you\'ve been interested in'; | |
foreach ($emails_array as $e_row) { | |
$this->emailSender($e_row, $new_comment_id, $subject, $message); | |
+ $subscriber_wp_user_id = $e_row['id']; | |
+ $subscriber_email = $e_row['email']; | |
+ do_action( 'wpdiscoz_notifyAllCommentSubscribers', $post_id, $new_comment_id, $subscriber_wp_user_id, $subscriber_email ); | |
} | |
} | |
- /** | |
- * notify on comment new replies | |
- */ | |
+ /** | |
+ * Send notifications for new replies to an individual comment | |
+ * (does this include grandchildren?) | |
+ * | |
+ * @param $parent_comment_id int | |
+ * @param $new_comment_id int | |
+ * @param $email string email address to exclude (the author?) | |
+ */ | |
public function notifyCommentSubscribers($parent_comment_id, $new_comment_id, $email) { | |
$emails_array = $this->dbManager->getNewReplyNotification($parent_comment_id, $email); | |
$subject = ($this->optionsSerialized->phrases['wc_new_reply_email_subject']) ? $this->optionsSerialized->phrases['wc_new_reply_email_subject'] : __('New Reply', 'wpdiscuz'); | |
$message = ($this->optionsSerialized->phrases['wc_new_reply_email_message']) ? $this->optionsSerialized->phrases['wc_new_reply_email_message'] : __('New reply on the discussion section you\'ve been interested in', 'wpdiscuz'); | |
foreach ($emails_array as $e_row) { | |
$this->emailSender($e_row, $new_comment_id, $subject, $message); | |
+ $subscriber_wp_user_id = $e_row['id']; | |
+ $subscriber_email = $e_row['email']; | |
+ do_action( 'wpdiscoz_notifyCommentSubscribers', $parent_comment_id, $new_comment_id, $subscriber_wp_user_id, $subscriber_email ); | |
} | |
} | |
+ /** | |
+ * Is this function deprecated? It doesn't seem to be called from anywhere in the plugin | |
+ * and it's trying to call methods that don't exist. | |
+ * | |
+ * @param $new_status string | |
+ * @param $old_status string | |
+ * @param $comment WP_Comment | |
+ */ | |
public function wc_notify_to_subscriber($new_status, $old_status, $comment) { | |
if ($old_status != $new_status) { | |
if ($new_status == 'approved') { | |
@@ -187,6 +221,12 @@ class WpdiscuzEmailHelper { | |
} | |
} | |
+ /** | |
+ * When a comment is approved from the admin comments.php or posts.php... notify the subscribers | |
+ * | |
+ * @param $comment_ID int | |
+ * @param $comment_approved bool | |
+ */ | |
public function notificationFromDashboard($comment_ID, $comment_approved) { | |
$referer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ''; | |
$commentdata = get_comment($comment_ID); | |
@@ -207,6 +247,11 @@ class WpdiscuzEmailHelper { | |
} | |
} | |
+ /** | |
+ * When a comment is approved (after being held for moderation)... notify the author | |
+ * | |
+ * @param $comment WP_Comment | |
+ */ | |
public function notifyOnApproving($comment) { | |
if ($comment) { | |
$user = $comment->user_id ? get_userdata($comment->user_id) : null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment