public function new_comment_notify($comment_id, $comment)
 {
     $parent = get_post_type($comment->comment_post_ID);
     //Admin email
     $admin_email = get_bloginfo('admin_email');
     $enable_send_copy = get_option('dwqa_subscrible_send_copy_to_admin');
     if (1 == $comment->comment_approved && ('dwqa-question' == $parent || 'dwqa-answer' == $parent)) {
         if ($parent == 'dwqa-question') {
             $enabled = get_option('dwqa_subscrible_enable_new_comment_question_notification', 1);
         } elseif ($parent == 'dwqa-answer') {
             $enabled = get_option('dwqa_subscrible_enable_new_comment_answer_notification', 1);
         }
         if (!$enabled) {
             return false;
         }
         $post_parent = get_post($comment->comment_post_ID);
         if (dwqa_is_anonymous($comment->comment_post_ID)) {
             $post_parent_email = get_post_meta($comment->comment_post_ID, '_dwqa_anonymous_email', true);
             if (!is_email($post_parent_email)) {
                 return false;
             }
         } else {
             // if user is not the author of question/answer, add user to followers list
             if ($post_parent->post_author != $comment->user_id) {
                 if (!dwqa_is_followed($post_parent->ID, $comment->user_id)) {
                     add_post_meta($post_parent->ID, '_dwqa_followers', $comment->user_id);
                 }
             }
             $post_parent_email = get_the_author_meta('user_email', $post_parent->post_author);
         }
         // To send HTML mail, the Content-type header must be set
         $headers = 'MIME-Version: 1.0' . "\r\n";
         $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
         //From email
         $from_email = get_option('dwqa_subscrible_from_address');
         if ($from_email) {
             $headers .= 'From: ' . $from_email . "\r\n";
         }
         if ($parent == 'dwqa-question') {
             $message = dwqa_get_mail_template('dwqa_subscrible_new_comment_question_email', 'new-comment-question');
             $subject = get_option('dwqa_subscrible_new_comment_question_email_subject', __('[{site_name}] You have a new comment for question {question_title}', 'dwqa'));
             $message = str_replace('{question_author}', get_the_author_meta('display_name', $post_parent->post_author), $message);
             $question = $post_parent;
         } else {
             $message = dwqa_get_mail_template('dwqa_subscrible_new_comment_answer_email', 'new-comment-answer');
             $subject = get_option('dwqa_subscrible_new_comment_answer_email_subject', __('[{site_name}] You have a new comment for answer', 'dwqa'));
             $message = str_replace('{answer_author}', get_the_author_meta('display_name', $post_parent->post_author), $message);
             $question_id = get_post_meta($post_parent->ID, '_question', true);
             $question = get_post($question_id);
         }
         $subject = str_replace('{site_name}', get_bloginfo('name'), $subject);
         $subject = str_replace('{question_title}', $question->post_title, $subject);
         $subject = str_replace('{question_id}', $question->ID, $subject);
         $subject = str_replace('{username}', get_the_author_meta('display_name', $comment->user_id), $subject);
         if (!$message) {
             return false;
         }
         // logo replace
         $logo = get_option('dwqa_subscrible_email_logo', '');
         $logo = $logo ? '<img src="' . $logo . '" alt="' . get_bloginfo('name') . '" style="max-width: 100%; height: auto;" />' : '';
         $subject = str_replace('{comment_author}', get_the_author_meta('display_name', $comment->user_id), $subject);
         $message = str_replace('{site_logo}', $logo, $message);
         $message = str_replace('{question_link}', get_permalink($question->ID), $message);
         $message = str_replace('{comment_link}', get_permalink($question->ID) . '#comment-' . $comment_id, $message);
         $message = str_replace('{question_title}', $question->post_title, $message);
         $message = str_replace('{comment_author_avatar}', get_avatar($comment->user_id, '60'), $message);
         $message = str_replace('{comment_author_link}', get_author_posts_url($comment->user_id), $message);
         $message = str_replace('{comment_author}', get_the_author_meta('display_name', $comment->user_id), $message);
         $message = str_replace('{comment_content}', $comment->comment_content, $message);
         $message = str_replace('{site_name}', get_bloginfo('name'), $message);
         $message = str_replace('{site_description}', get_bloginfo('description'), $message);
         $message = str_replace('{site_url}', site_url(), $message);
         if ($parent == 'dwqa-question') {
             $enable_notify = get_option('dwqa_subscrible_enable_new_comment_question_followers_notify', true);
         } else {
             $enable_notify = get_option('dwqa_subscrible_enable_new_comment_answer_followers_notification', true);
         }
         if ($enable_notify) {
             //Follower email task
             $followers = get_post_meta($post_parent->ID, '_dwqa_followers');
             $comment_email = get_the_author_meta('user_email', $comment->user_id);
             if ($parent == 'dwqa-question') {
                 $message_to_follower = dwqa_get_mail_template('dwqa_subscrible_new_comment_question_followers_email', 'new-comment-question');
                 $follow_subject = get_option('dwqa_subscrible_new_comment_question_followers_email_subject', __('[{site_name}] You have a new comment for question {question_title}', 'dwqa'));
                 $message_to_follower = str_replace('{question_author}', get_the_author_meta('display_name', $post_parent->post_author), $message_to_follower);
                 $question = $post_parent;
             } else {
                 $message_to_follower = dwqa_get_mail_template('dwqa_subscrible_new_comment_answer_followers_email', 'new-comment-answer');
                 $follow_subject = get_option('dwqa_subscrible_new_comment_answer_followers_email_subject', __('[{site_name}] You have a new comment for answer', 'dwqa'));
                 $message_to_follower = str_replace('{answer_author}', get_the_author_meta('display_name', $post_parent->post_author), $message_to_follower);
             }
             $follow_subject = str_replace('{site_name}', get_bloginfo('name'), $follow_subject);
             $follow_subject = str_replace('{question_title}', $question->post_title, $follow_subject);
             $follow_subject = str_replace('{question_id}', $question->ID, $follow_subject);
             $follow_subject = str_replace('{username}', get_the_author_meta('display_name', $comment->user_id), $follow_subject);
             $follow_subject = str_replace('{comment_author}', get_the_author_meta('display_name', $comment->user_id), $follow_subject);
             $message_to_follower = str_replace('{site_logo}', $logo, $message_to_follower);
             $message_to_follower = str_replace('{question_link}', get_permalink($question->ID), $message_to_follower);
             $comment_link = get_permalink($question->ID) . '#comment-' . $comment_id;
             $message_to_follower = str_replace('{comment_link}', $comment_link, $message_to_follower);
             $message_to_follower = str_replace('{question_title}', $question->post_title, $message_to_follower);
             $message_to_follower = str_replace('{comment_author_avatar}', get_avatar($comment->user_id, '60'), $message_to_follower);
             $message_to_follower = str_replace('{comment_author_link}', get_author_posts_url($comment->user_id), $message_to_follower);
             $message_to_follower = str_replace('{comment_author}', get_the_author_meta('display_name', $comment->user_id), $message_to_follower);
             $message_to_follower = str_replace('{comment_content}', $comment->comment_content, $message_to_follower);
             $message_to_follower = str_replace('{site_name}', get_bloginfo('name'), $message_to_follower);
             $message_to_follower = str_replace('{site_description}', get_bloginfo('description'), $message_to_follower);
             $message_to_follower = str_replace('{site_url}', site_url(), $message_to_follower);
             if (!empty($followers)) {
                 foreach ($followers as $follower) {
                     $follower = (int) $follower;
                     $user_data = get_userdata($follower);
                     if ($user_data) {
                         $follow_email = $user_data->user_email;
                         $follower_name = $user_data->display_name;
                         if ($follow_email && $follow_email != $post_parent_email && $follow_email != $comment_email) {
                             $message_to_each_follower = str_replace('{follower}', $follower_name, $message_to_follower);
                             wp_mail($follow_email, $follow_subject, $message_to_each_follower, $headers);
                             if ($enable_send_copy && $follow_email != $admin_email) {
                                 wp_mail($admin_email, $follow_subject, $message_to_each_follower, $headers);
                             }
                         }
                     }
                 }
             }
         }
         if ($post_parent->post_author != $comment->user_id) {
             wp_mail($post_parent_email, $subject, $message, $headers);
             if ($enable_send_copy && $admin_email != $post_parent_email) {
                 wp_mail($admin_email, $subject, $message, $headers);
             }
         }
     }
 }
Example #2
0
function dwqa_subscrible_new_comment_answer_followers_email_display()
{
    echo '<label for="dwqa_subscrible_new_comment_answer_followers_email">' . __('Email Content', 'dwqa') . '<br>';
    $content = dwqa_get_mail_template('dwqa_subscrible_new_comment_answer_followers_email', 'new-comment-answer-followers');
    wp_editor($content, 'dwqa_subscrible_new_comment_answer_followers_email', array('wpautop' => false, 'tinymce' => array('content_css' => DWQA_URI . 'assets/css/email-template-editor.css')));
    echo '<p><input data-template="new-comment-answer-followers.html" type="button" class="button dwqa-reset-email-template" value="Reset Template"></p>';
    echo '<div class="description">
		Enter the email that is sent to Administrator when have new answer on your site. HTML is accepted. Available template settings:<br>
		<strong>{site_logo}</strong> - Your site logo <br />
		<strong>{site_name}</strong> - Your site name <br />
		<strong>{site_description}</strong> - Your site description <br />
		<strong>{answer_author}</strong> - Answer Author Name <br />
		<strong>{comment_author}</strong> - Comment Author Name <br />
		<strong>{comment_author_avatar}</strong> - Comment Author Avatar <br />
		<strong>{comment_author_link}</strong> - Comment Author Link <br />
		<strong>{question_title}</strong> - Question Title <br />
		<strong>{question_link}</strong> - Question Link <br />
		<strong>{comment_content}</strong> - Comment Content <br />
	</div>';
    echo '</label>';
}