如何更改自定义帖子类型的评论电子邮件通知的收件人和内容?

时间:2016-01-21 作者:Teo Maragakis

我正在构建一个票证系统,并希望使用评论线程作为票证的讨论。每张票据涉及三个用户:

客户

客户端打开票据,主管将其分配给操作员这三个都可以添加到讨论中,当其中一个添加评论时,我想用自定义消息通知另外两个。我该怎么做?

1 个回复
SO网友:Teo Maragakis

我做了很长一段路,在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...\');
  }
}