/**
  * Main PH_Emails Instance.
  *
  * Ensures only one instance of PH_Emails is loaded or can be loaded.
  *
  * @since 1.0.0
  * @static
  * @return PH_Emails Main instance
  */
 public static function instance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Preview email template.
  *
  * @return string
  */
 public function preview_emails()
 {
     if (isset($_GET['preview_propertyhive_email'])) {
         if (!wp_verify_nonce($_REQUEST['_wpnonce'], 'propertyhive-matching-properties')) {
             die('Security check');
         }
         // get the preview email content
         $email_property_ids = explode(",", $_POST['email_property_id']);
         $body = stripslashes($_POST['body']);
         $body = str_replace("[contact_name]", get_the_title($_GET['contact_id']), $body);
         $body = str_replace("[property_count]", count($email_property_ids) . ' propert' . (count($email_property_ids) != 1 ? 'ies' : 'y'), $body);
         if (strpos($body, '[properties]') !== FALSE) {
             ob_start();
             if (!empty($email_property_ids)) {
                 foreach ($email_property_ids as $email_property_id) {
                     $property = new PH_Property((int) $email_property_id);
                     ph_get_template('emails/applicant-match-property.php', array('property' => $property));
                 }
             }
             $body = str_replace("[properties]", ob_get_clean(), $body);
         }
         // create a new email
         $email = new PH_Emails();
         // wrap the content with the email template and then add styles
         $message = apply_filters('propertyhive_mail_content', $email->style_inline($email->wrap_message($body)));
         // print the preview email
         echo $message;
         exit;
     }
 }