Created
February 28, 2013 18:38
-
-
Save grex22/5059023 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
/** | |
* Custom code added to P2 to enable email notifications | |
* when a user is @mentioned in the site. | |
* | |
* Original at http://trepmal.com/2011/06/24/using-wordpress-multisite-p2-and-more/ | |
* and modified from there. | |
*/ | |
add_action('publish_post','send_email_notification_once',9); | |
function send_email_notification_once($postID) { | |
$post = get_post($postID); | |
$author = get_userdata($post->post_author); | |
global $p2; | |
$mentions = $p2->components['mentions']->find_mentions($post->post_content); | |
$permalink = get_permalink($postID); | |
$blog_title = get_bloginfo('name'); | |
foreach ( $mentions as $match ) { | |
$email = get_user_by('slug',$match)->user_email; | |
$message = "You have been mentioned in this post:\n $permalink \n\n {$post->post_content} "; | |
wp_mail($email, "[$blog_title] You've been mentioned by {$author->display_name}", $message); | |
} | |
} | |
add_action('comment_post','send_email_notification_once_comment',9); | |
function send_email_notification_once_comment($commentID){ | |
$comment = get_comment($commentID); | |
global $p2; | |
$mentions = $p2->components['mentions']->find_mentions($comment->comment_content); | |
$permalink = get_permalink($comment->comment_post_ID); | |
$blog_title = get_bloginfo('name'); | |
foreach ( $mentions as $match ) { | |
$email = get_user_by('slug',$match)->user_email; | |
$message = "You have been mentioned by {$comment->comment_author} in this comment:\n $permalink \n\n {$comment->comment_content} "; | |
$headers = 'From: Sprouts <[email protected]>' . "\r\n"; | |
wp_mail($email, "[$blog_title] You've been mentioned in a comment by {$comment->comment_author}", $message, $headers); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment