rohitkc7

Comments

Jan 5th, 2022 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.88 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4.             // Here, we insert the replies as comments to their parent email.
  5.                  if ((!empty($mail['header']->references )) && (preg_replace('~[<]~','',strstr($mail['header']->references, '@',true))) == (preg_replace('~[<]~','',strstr($mail['header']->references, '@',true))))    
  6.                 {
  7.                   //echo htmlentities($mail['header']->message_id);
  8.  
  9.                 //$posts = get_posts();
  10.                    
  11.                     $comment_exists = (bool) get_comments( array(
  12.     'type'       => 'email_replies',
  13.     'meta_key'   => 'message_id',
  14.     'meta_value' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true)),
  15.     'count'      => true, // this means we're retrieving the number of comments only
  16. ) );
  17.  
  18.                     if ( ! $comment_exists ) {
  19.              $posts = get_posts(  array(
  20.                     'post_type'  => 'faqpress-tickets',
  21.                     'meta_key'   => 'ticket_id',
  22.                     'meta_value' => preg_replace('~[<]~','',strstr($mail['header']->references, '@',true)),
  23.                 )  );
  24.  
  25.             if ( ! empty( $posts )   ) {
  26.                 $comment_array = array(
  27.                     'comment_content' => $mail['body'],
  28.                     'comment_post_ID' => $posts[0]->ID,
  29.                     'comment_author'  => ucwords(strstr($mail['header']->fromaddress, '<',true)),
  30.                     'comment_author_email' => preg_replace('~[<>]~', '', strstr($mail['header']->fromaddress, '<')),
  31.                     'comment_type'  => 'email_replies',
  32.                     'comment_date'  => $mail['header']->Date,
  33.                     'comment_meta'  => array(
  34.                         'message_id' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true))),
  35.                 );
  36.                   wp_insert_comment($comment_array);
  37.             }
  38.             }
  39.     }
Add Comment
Please, Sign In to add comment