Advertisement
Guest User

Untitled

a guest
Aug 10th, 2016
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. function codex15766_custom_email_message() {
  2.  
  3. // Do not create if it already exists and is not in the trash
  4. $post_exists = post_exists( '[{{{site.name}}}] New post comment.' );
  5.  
  6. if ( $post_exists != 0 && get_post_status( $post_exists ) == 'publish' )
  7. return;
  8.  
  9. // Create post object
  10. $my_post = array(
  11. 'post_title' => __( '[{{{site.name}}}] New post comment.', 'buddypress' ),
  12. 'post_content' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // HTML email content.
  13. 'post_excerpt' => __( '{{commenter.name}} commented on your blog post.', 'buddypress' ), // Plain text email content.
  14. 'post_status' => 'publish',
  15. 'post_type' => bp_get_email_post_type() // this is the post type for emails
  16. );
  17.  
  18. // Insert the email post into the database
  19. $post_id = wp_insert_post( $my_post );
  20.  
  21. if ( $post_id ) {
  22. // add our email to the taxonomy term 'post_received_comment'
  23. // Email is a custom post type, therefore use wp_set_object_terms
  24.  
  25. $tt_ids = wp_set_object_terms( $post_id, 'post_received_comment', bp_get_email_tax_type() );
  26. foreach ( $tt_ids as $tt_id ) {
  27. $term = get_term_by( 'term_taxonomy_id', (int) $tt_id, bp_get_email_tax_type() );
  28. wp_update_term( (int) $term->term_id, bp_get_email_tax_type(), array(
  29. 'description' => 'A member comments on a posts',
  30. ) );
  31. }
  32. }
  33.  
  34. }
  35. add_action( 'bp_core_install_emails', 'codex15766_custom_email_message' );
  36.  
  37. function bp_comment_inserted( $comment_id, $comment_object ) {
  38.  
  39. if ( $comment_object ) {
  40. // get the post data
  41. $post = get_post( $comment_object->comment_post_ID );
  42. // add tokens to parse in email
  43. $args = array(
  44. 'tokens' => array(
  45. 'site.name' => get_bloginfo( 'name' ),
  46. 'commenter.name' => $comment_object->comment_author,
  47. ),
  48. );
  49. // send args and user idto recieve email
  50. $r = bp_send_email( 'post_recieved_comment', (int) $post->post_author, $args );
  51. }
  52. }
  53. add_action( 'wp_insert_comment','bp_comment_inserted', 99, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement