Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Here, we insert the replies as comments to their parent email.
- if ((!empty($mail['header']->references )) && (preg_replace('~[<]~','',strstr($mail['header']->references, '@',true))) == (preg_replace('~[<]~','',strstr($mail['header']->references, '@',true))))
- {
- //echo htmlentities($mail['header']->message_id);
- //$posts = get_posts();
- $comment_exists = (bool) get_comments( array(
- 'type' => 'email_replies',
- 'meta_key' => 'message_id',
- 'meta_value' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true)),
- 'count' => true, // this means we're retrieving the number of comments only
- ) );
- if ( ! $comment_exists ) {
- $posts = get_posts( array(
- 'post_type' => 'faqpress-tickets',
- 'meta_key' => 'ticket_id',
- 'meta_value' => preg_replace('~[<]~','',strstr($mail['header']->references, '@',true)),
- ) );
- if ( ! empty( $posts ) ) {
- $comment_array = array(
- 'comment_content' => $mail['body'],
- 'comment_post_ID' => $posts[0]->ID,
- 'comment_author' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
- 'comment_author_email' => preg_replace('~[<>]~', '', strstr($mail['header']->fromaddress, '<')),
- 'comment_type' => 'email_replies',
- 'comment_date' => $mail['header']->Date,
- 'comment_meta' => array(
- 'message_id' => preg_replace('~[<]~','',strstr($mail['header']->message_id, '@',true))),
- );
- wp_insert_comment($comment_array);
- }
- }
- }
Add Comment
Please, Sign In to add comment