THIS THREAD HAS BEEN CLOSED.

Send email notifications for comments in Questions and Answers (implemented code inside)

Updated on Aug 25, 2016 in QAEngine
3 on Jul 29, 2016

Since email notifications feature wasn’t available on the theme, I created for my website. I am gonna share it here if anyone want to replicate it or if the owners of the theme want to include it on the original theme.

On file /includes/front.php and on line 793, add the following:

@SSK, please add at least the hook on this file, so we don’t have to edit it everything you update the theme. The rest is feasible on the child theme.

do_action('send_email_on_comments', $args);

Then on your functions.php of your child theme, add the following code and edit the message as you wish:

add_action('send_email_on_comments','create_email_for_comments');
function create_email_for_comments($args) {
// Email content for comments
 // Send email to author of question
 $post = get_post($args['post_parent']);
 // Get author info
 $author_id = $post->post_author;
 $user = new WP_User($author_id);
// details for questions
 if( $post->post_type == "question" ) {
 $message = 'Hello [display_name],<br><br>The question <strong>"[question_title]"</strong> you are following has a new comment. <br><br>Click the link below to view the question.<br><br>[question_link]<br><br>The comment: <br><br>[comment_content] <br><br>Sincerely,<br>[blogname]';
 $subject = __("Your question has received a new comment",ET_DOMAIN);
 $link = get_permalink($args['post_parent']);
 $question_title = $post->post_title;
 // details for answers
 } else {
 $message = 'Hello [display_name],<br><br>The answer on the question <strong>"[question_title]"</strong> you are following has a new comment. <br><br>Click the link below to view the question.<br><br>[question_link]<br><br>The comment: <br><br>[comment_content] <br><br>Sincerely,<br>[blogname]';
 $subject = __("Your answer has received a new comment",ET_DOMAIN);
 $question = wp_get_post_parent_id($args['post_parent']);
 $link = get_permalink($question);
 $question_title = substr($post->post_title, 4);
 }
 $question_link = '<a href="'. $link .'">'. $link .'</a>';
 $message = stripslashes($message);
 $message = str_ireplace('[question_link]', $question_link, $message);
 $message = str_ireplace('[question_title]', $question_title, $message);
 $message = str_ireplace('[comment_content]', $args['comment_content'], $message);
// Email subject
 // Send email
 qa_email_notify($user, $subject, $message);
 }
  • Liked by
0 on Aug 1, 2016

Hi

Thank you for posting in and I really appreciate your work on this issue. I did move forward this thread to our developer. Hope it will implement in next version soon.

Many Thank

  • Liked by
Cancel
0 on Aug 24, 2016

It did not work for me .

The code on /includes/front.php is like this?

// Email subject
do_action('send_email_on_comments', $args);
$subject = __("Your question has recieved a new answer",ET_DOMAIN);
// Send email
qa_email_notify($user, $subject, $message);
}
  • Liked by
Cancel
0 on Aug 25, 2016

Hi there,

Our developer confirmed that the hook has been added and it will available in the next update.

@victor: Currently your code is not available in the current version. Kindly wait the next version and use this code.

 

Thank you!

  • Liked by
Cancel
Loading more replies
Posting & Replying function will be deactivated from 3pm GMT+7 12th Sep.
Read More