Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez
Last active July 4, 2018 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DavidPeralvarez/ae024d907105a56557c5972f7ad2df2f to your computer and use it in GitHub Desktop.
Save DavidPeralvarez/ae024d907105a56557c5972f7ad2df2f to your computer and use it in GitHub Desktop.
Lesson Reply Notification 6
<?php
/*
Plugin Name: Lesson Reply Notification
Description: Send and email to the student, when he receives a response
Author: David Perálvarez
Version: 1.0
Author URI: https://silicodevalley.com
*/
add_action( 'wp_insert_comment', 'scv_comment_notification', 99, 2 );
function scv_comment_notification( $commentId, $comment ) {
if (($comment->comment_approved == 1) && ($comment->comment_parent > 0)) {
$parent = get_comment($comment->comment_parent);
$email = $parent->comment_author_email;
// Check comments are from lessons
$postId = $parent->comment_post_ID;
$postType = get_post_type($postId);
if($postType == 'lesson'){
// Parent comment author == new comment author
// In this case, we don't send a notification.
if ($email == $comment->comment_author_email) return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment