Created
February 15, 2016 18:22
-
-
Save modemlooper/8aeb3b03e2a58f1a129e to your computer and use it in GitHub Desktop.
email bp comment
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
function bp_custom_email_message() { | |
// Create post object | |
$my_post = array( | |
'post_title' => __( '[{{{site.name}}}] New post comment.', 'buddypress' ), | |
'post_content' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), | |
'post_status' => 'publish', | |
'post_type' => bp_get_email_post_type() // this is the post type for emails | |
); | |
// Insert the email post into the database | |
$post = wp_insert_post( $my_post ); | |
if ( $post ) { | |
// add our email to the taxonomy term 'post_recieved_comment' | |
$term_id = wp_set_post_terms( $post, 'post_recieved_comment', bp_get_email_tax_type() ); | |
// update the term's description | |
wp_update_term( $term_id[0], bp_get_email_tax_type(), array( 'description' => 'A member comments on a posts' ) ); | |
} | |
} | |
add_action( 'bp_core_install_emails', 'bp_custom_email_message' ); | |
function bp_comment_inserted( $comment_id, $comment_object ) { | |
if ( $comment_object ) { | |
// get the post data | |
$post = get_post( $comment_object->comment_post_ID ); | |
// add tokens to parse in email | |
$args = array( | |
'tokens' => array( | |
'site.name' => get_bloginfo( 'name' ), | |
'commenter.name' => $comment_object->comment_author, | |
), | |
); | |
// send args and user idto recieve email | |
bp_send_email( 'post_recieved_comment', (int) $post->post_author, $args ); | |
} | |
} | |
add_action( 'wp_insert_comment','bp_comment_inserted', 99, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment