function Invitation_Collaborators()
 {
     $Workroom_Id = $_POST['Workroom_Id'];
     $Action = $_POST['Action'];
     $Collaborator_Id = $_POST['Collaborator_Id'];
     //==============
     if ($Action == 'Invited') {
         $Item_ID = get_item_id_by_workroom_id($Workroom_Id);
         //get_post_meta($Workroom_Id,'Unfinished_Item_ID',true);
         $author_id = get_post_field('post_author', $Workroom_Id);
         $to_author_id = $Collaborator_Id;
         $Alert_Title = 'You have received Invitation From ' . get_the_author_meta('display_name', $author_id) . ' to join in his workroom';
         //Generate Alert Id
         $Alert_Id = uniqid();
         //End Alert Id
         $InvAlerts = new stdClass();
         $InvAlerts->Collaborator_Name = get_the_author_meta('display_name', $to_author_id);
         $InvAlerts->Workroom_Name = get_the_title($Workroom_Id);
         $InvAlerts->Invitation_Accept_Link = $this->Get_Invitation_Accept_Link($Workroom_Id, $to_author_id, $Alert_Id);
         $InvAlerts->Invitation_Sender = get_the_author_meta('display_name', $author_id);
         ob_start();
         include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-invitation-email-template.php';
         $Get_Template = ob_get_clean();
         ob_start();
         include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-email-css.php';
         $css = ob_get_clean();
         wp_mail('*****@*****.**', $Alert_Title, $css . $Get_Template);
         wp_mail(get_the_author_meta('user_email', $to_author_id), $Alert_Title, $css . $Get_Template);
         //Add Alerts
         $collection = array('Edd_Alert_Message' => $Get_Template, 'Edd_Alert_Title' => $Alert_Title, 'Edd_Alert_To' => $to_author_id, 'Edd_Alert_Id' => $Alert_Id, 'Edd_Alert_From' => $author_id, 'Edd_Alert_Message_Url' => $this->Get_Invitation_Accept_Link($Workroom_Id, $to_author_id, $Alert_Id, false));
         $this->update_collaborators_invitation($Workroom_Id, 'Invited', $to_author_id, $Alert_Id);
         edd_add_alerts($collection);
         //End Alerts
         $status = array('Collaborator_Id' => $Collaborator_Id);
         echo json_encode($status);
     }
 }
function check_emails()
{
    $emails = read_emails();
    foreach ($emails as $email) {
        $startsAt = strpos($emails[0]->Email_Subject, "[") + strlen("[");
        $endsAt = strpos($emails[0]->Email_Subject, "]", $startsAt);
        $result = substr($emails[0]->Email_Subject, $startsAt, $endsAt - $startsAt);
        if ($result != '') {
            $check_to_insert = explode(':', $result);
            if (isset($check_to_insert[0]) && isset($check_to_insert[1]) && $check_to_insert[0] != '' && $check_to_insert[1] != '') {
                $Email_Type = $check_to_insert[0];
                $Workroom_ID = $check_to_insert[1];
                $Author_ID = $check_to_insert[2];
                if (strtolower($check_to_insert[0]) == 'message') {
                    $post = array('post_content' => nl2br($email->Email_Body), 'post_name' => $email->Email_Subject, 'post_title' => $email->Email_Subject, 'post_status' => 'publish', 'post_type' => 'collab-msg', 'post_author' => $Author_ID, 'ping_status' => 'close', 'post_parent' => '0', 'menu_order' => '0', 'to_ping' => '', 'pinged' => '', 'post_password' => '', 'comment_status' => 'closed');
                    $page_id = wp_insert_post($post);
                    //if(isset($this->posts['attachments']) && is_array($this->posts['attachments'])){
                    //update_post_meta($page_id, '_wp_collaboration_attachments',$this->posts['attachments']);
                    //}
                    update_post_meta($page_id, 'Workroom_Id', $Workroom_ID);
                    $Alert_Id = uniqid();
                    $author_id = $Author_ID;
                    $Workroom_Id = $Workroom_ID;
                    $Teams = get_teams_as_workroom($Workroom_Id);
                    foreach ($Teams as $team) {
                        $Alert_Title = '' . get_the_author_meta('display_name', $author_id) . ' posted a message in ' . get_the_title($Workroom_Id) . identity(array('Workroom_Id' => $Workroom_Id, 'Type' => 'Message', 'Collaborator_Id' => $team->Collaborator_Id));
                        if ($team->Collaborator_Id == $author_id) {
                            continue 1;
                        }
                        $MessageAlert = new stdClass();
                        $MessageAlert->Collaborator_Name = get_the_author_meta('display_name', $team->Collaborator_Id);
                        $MessageAlert->Workroom_Name = get_the_title($Workroom_Id);
                        $MessageAlert->Workroom_Message = nl2br($email->Email_Body);
                        $MessageAlert->Notification_Link = Get_Message_Notification_Link($Workroom_Id, $team->Collaborator_Id, $Alert_Id);
                        $MessageAlert->Notification_From = get_the_author_meta('display_name', $author_id);
                        ob_start();
                        include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-message-post-template.php';
                        $Get_Template = ob_get_clean();
                        ob_start();
                        include collaboration_plugin_dir . 'templates/frontend/emails/collaboration-email-css.php';
                        $css = ob_get_clean();
                        //Add Alert
                        $collection = array('Edd_Alert_Message' => $Get_Template, 'Edd_Alert_Title' => $Alert_Title, 'Edd_Alert_Id' => $Alert_Id, 'Edd_Alert_To' => $team->Collaborator_Id, 'Edd_Alert_From' => $author_id, 'Edd_Alert_Message_Url' => Get_Message_Notification_Link($Workroom_Id, $team->Collaborator_Id, $Alert_Id, false));
                        edd_add_alerts($collection);
                        //End Add Alerts
                        wp_mail('*****@*****.**', $Alert_Title, $css . $Get_Template);
                        wp_mail(get_the_author_meta('user_email', $team->Collaborator_Id), $Alert_Title, $css . $Get_Template);
                    }
                } else {
                    if (strtolower($check_to_insert[0]) == 'report') {
                        $Alert_Title = '' . get_the_author_meta('display_name', $Author_ID) . ' sent you a message' . identity(array('Workroom_Id' => $Workroom_ID, 'Type' => 'Report', 'Collaborator_Id' => $author_id));
                        save_reported(nl2br($email->Email_Body), $Alert_Title, $Workroom_ID, $Author_ID);
                    }
                }
                //print_r($email);
            }
        }
    }
    die;
}