1

I am building a ticket system and would like to use the comment threads as the discussion for the ticket. There are three users involved in each ticket:

  1. The client.
  2. The support operator.
  3. The support supervisor.

The order of things is:

  1. Client opens ticket
  2. Supervisor assigns it to operator.
  3. Operator works on it.

All three can add to the discussion and I would like to notify the other two with a custom message, when one adds a comment. How can I do this?

0

I did it the long way, with help from a related WordPress.org support thread:

add_action('comment_post', 'notify_author_of_reply', 10, 2);

function notify_author_of_reply($comment_id, $approved){

  $comment = get_comment($comment_id);
  $post_id = $comment->comment_post_ID;
  $post = get_post($post_id);

  if($approved && (get_post_type( $post_id )=='ticket')) {

    $supervisor = get_userdata( get_post_meta($post->ID, 'assigned_by', true) );
    $operator = get_userdata( get_post_meta($post->ID, 'assigned_to', true) );
    $client = get_userdata( $post->post_author );

    $recipients = array(
      $client->user_email,
      $supervisor->user_email,
      $operator->user_email
    );

    $current_user = wp_get_current_user();

    if (($key = array_search($current_user->user_email, $recipients)) !== false) {
      unset($recipients[$key]);
    }
    wp_mail($recipients, 'New comment', 'Dude you got a reply...');
  }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.