Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function codex15766_custom_email_message() {
- // Do not create if it already exists and is not in the trash
- $post_exists = post_exists( '[{{{site.name}}}] New post comment.' );
- if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' )
- return;
- // Create post object
- $my_post = array(
- 'post_title' => __( '[{{{site.name}}}] New post comment.', 'buddypress' ),
- 'post_content' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // HTML email content.
- 'post_excerpt' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // Plain text email content.
- '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_id = wp_insert_post( $my_post );
- if ( $post_id ) {
- // add our email to the taxonomy term 'post_received_comment'
- // Email is a custom post type, therefore use wp_set_object_terms
- $tt_ids = wp_set_object_terms( $post_id, 'post_received_comment', bp_get_email_tax_type() );
- foreach ( $tt_ids as $tt_id ) {
- $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
- wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
- 'description' => 'A member comments on a posts',
- ) );
- }
- }
- }
- add_action( 'bp_core_install_emails', 'codex15766_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
- $r = bp_send_email( 'post_recieved_comment', (int) $post->post_author, $args );
- }
- }
- add_action( 'wp_insert_comment','bp_comment_inserted', 99, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement