Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function checkEmailAlreadyExists( $message_id ) {
- $posts_with_meta = get_posts( array(
- 'posts_per_page' => 1, // we only want to check if any exists, so don't need to get all of them
- 'post_type' => 'faqpress-tickets',
- 'meta_key' => 'ticket_id',
- 'meta_value' => $message_id,
- 'fields' => 'ids', // we don't need it's content, etc.
- ) );
- return ( count( $posts_with_meta ) ) ? true : false;
- }
- $total = $emails->total_msg();
- for ( $j=1; $j <= $total; $j++ ) {
- $mail = $emails->get( $j );
- if ( !empty( $mail['header']->message_id ) && !checkEmailAlreadyExists( $mail['header']->message_id ) ) {
- $post_array = array(
- 'post_content' => $mail['body'],
- 'post_title' => $mail['header']->subject,
- 'post_type' => 'faqpress-tickets',
- 'post_author' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
- 'post_status' => 'publish',
- 'meta_input' => array(
- 'User' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
- 'From' => preg_replace('~[<>]~', '', strstr($mail['header']->fromaddress, '<')),
- 'Email' => $mail['header']->Date,
- 'ticket_id' => $mail['header']->message_id,
- ),
- );
- //wp_insert_post( $post_array );
- }
- }
- $posts = get_posts( array(
- 'post_type' => 'faqpress-tickets',
- 'meta_key' => 'ticket_id',
- 'meta_value' => $mail['header']->message_id,
- ) );
- if(! empty( $posts )){
- for($j = 1; $j <= $total; $j++){
- $mail = $emails->get($j);
- 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);
- $comment_array = array(
- 'comment_content' => $mail['body'],
- 'comment_post_ID' => $posts,
- );
- //wp_insert_comment($comment_array);
- }
- }
- }
- /***
- function faqpress_author($data,$post_array){
- }
- add_filter("wp_insert_post_data", "faqpress_author", 10, 2);
- $postType = "faqpress-tickets";
- add_filter("wp_insert_post_data" . $postType, function ($data, $postarr) {
- if (0 === $postarr["ID"]) { // it's a new post
- $data["post_author"] = ucwords(strstr($mail['header']->fromaddress, '<',true));
- }
- return $data;
- }, 10, 2);
- ***/
- //Get all users and if user exists get username and email or else create new user as support customer.
- $user = strstr($mail['header']->fromaddress, '<',true);
- $email = $mail['header']->fromaddress;
- for ($j=1; $j < $total; $j++) {
- $mail = $emails-> get($j);
- if(email_exists($email)){
- add_post_meta($post_id, 'faqpress_ticket_username', $email, True);
- add_post_meta($post_id, 'faqpress_ticket_email', $user, True);
- }
- else{
- $userdata = array(
- 'user_login' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
- 'user_pass' => '',
- 'user_nicename' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
- 'display_name' => ucwords(strstr($mail['header']->fromaddress, '<',true)),
- 'user_email' => strstr($mail['header']->fromaddress, '<'),
- 'role' => 'support_customer',
- );
- wp_insert_user($userdata);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement