Last active
July 4, 2018 11:46
-
-
Save DavidPeralvarez/f36cc0a501c568162f9dad7af3fc2486 to your computer and use it in GitHub Desktop.
Lesson Reply Notification
This file contains hidden or 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
<?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 | |
*/ | |
apply_filters( 'wp_mail_from', '[email protected]' ); | |
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; | |
ob_start(); | |
?> | |
<p><?php printf(__('Muy buenas %s', 'scv'), $parent->comment_author) ?>,</p> | |
<p><?php printf(__('%s ha respondido a tu duda de la lección: ', 'scv'), $comment->comment_author) ?> | |
<a href="<?php echo get_permalink($parent->comment_post_ID) ?>"><?php echo get_the_title($parent->comment_post_ID) ?></a></p> | |
<p><em><?php echo esc_html($comment->comment_content) ?></em></p> | |
<p><a href="<?php echo get_comment_link($parent->comment_ID) ?>"><?php echo __('Ver respuesta dentro del sitio.', 'scv') ?></a></p> | |
<?php | |
$body = ob_get_clean(); | |
$subject = __( '[Club SiliCodeValley] Nueva respuesta a tu duda', 'scv' ); | |
$headers = array('Content-Type: text/html; charset=UTF-8'); | |
wp_mail($email, $subject, $body, $headers ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment