Ejemplo n.º 1
0
 /**
  * Create a new follow-up email
  *
  * @since 4.1
  * @param array $data
  * @return array
  * @throws FUE_API_Exception
  */
 public function create_email($data)
 {
     $data = apply_filters('fue_api_create_email_data', $data, $this);
     if (!empty($data['status'])) {
         $data['status'] = $this->fix_status_string($data['status']);
     }
     $id = fue_create_email($data);
     // Checks for an error in the email creation.
     if (is_wp_error($id)) {
         throw new FUE_API_Exception('fue_api_cannot_create_email', $id->get_error_message(), 400);
     }
     do_action('fue_api_created_email', $id, $data);
     $this->server->send_status(201);
     return $this->get_email($id);
 }
Ejemplo n.º 2
0
 *
 * Old emails with deprecated email types did not get imported in update-7.0.
 * This update addresses that issue by importing old and existing emails with
 * the old email types and converting them to the storewide type.
 */
if (!defined('ABSPATH')) {
    exit;
    // Exit if accessed directly
}
global $wpdb;
$table_check = $wpdb->get_results("SHOW TABLES LIKE '{$wpdb->prefix}followup_emails'");
if (count($table_check)) {
    // convert emails to use the new post type
    $emails = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}followup_emails WHERE email_type IN ('normal', 'product', 'generic')");
    $status_map = array(-1 => FUE_Email::STATUS_ARCHIVED, 0 => FUE_Email::STATUS_INACTIVE, 1 => FUE_Email::STATUS_ACTIVE);
    foreach ($emails as $email) {
        // convert normal, product and generic types to storewide
        if (in_array($email->email_type, array('normal', 'product', 'generic'))) {
            $email->email_type = 'storewide';
        }
        $args = array('name' => $email->name, 'type' => $email->email_type, 'subject' => $email->subject, 'message' => $email->message, 'status' => $status_map[$email->status], 'priority' => $email->priority, 'product_id' => $email->product_id, 'category_id' => $email->category_id, 'interval_num' => $email->interval_num, 'interval_duration' => $email->interval_duration, 'interval_type' => $email->interval_type, 'send_date' => $email->send_date, 'send_date_hour' => $email->send_date_hour, 'send_date_minute' => $email->send_date_minute, 'tracking_code' => $email->tracking_code, 'usage_count' => $email->usage_count, 'always_send' => $email->always_send, 'meta' => $email->meta);
        $old_email_id = $email->id;
        $new_email_id = fue_create_email($args);
        // search for all instances of the old email ID and replace them with the new ID
        $wpdb->update($wpdb->prefix . 'followup_email_coupons', array('email_id' => $new_email_id), array('email_id' => $old_email_id));
        $wpdb->update($wpdb->prefix . 'followup_email_excludes', array('email_id' => $new_email_id), array('email_id' => $old_email_id));
        $wpdb->update($wpdb->prefix . 'followup_email_logs', array('email_id' => $new_email_id), array('email_id' => $old_email_id));
        $wpdb->update($wpdb->prefix . 'followup_email_orders', array('email_id' => $new_email_id), array('email_id' => $old_email_id));
        $wpdb->update($wpdb->prefix . 'followup_email_tracking', array('email_id' => $new_email_id), array('email_id' => $old_email_id));
    }
}
Ejemplo n.º 3
0
 /**
  * update_settings method
  */
 static function update_settings()
 {
     $wpdb = Follow_Up_Emails::instance()->wpdb;
     $section = $_POST['section'];
     $imported = '';
     if ($section == 'email') {
         // capability
         if (isset($_POST['roles'])) {
             $roles = get_editable_roles();
             $wp_roles = new WP_Roles();
             foreach ($roles as $key => $role) {
                 if (in_array($key, $_POST['roles'])) {
                     $wp_roles->add_cap($key, 'manage_follow_up_emails');
                 } else {
                     $wp_roles->remove_cap($key, 'manage_follow_up_emails');
                 }
             }
             // make sure the admin has this capability
             $wp_roles->add_cap('administrator', 'manage_follow_up_emails');
         }
         do_action('fue_settings_email_save', $_POST);
     } elseif ($section == 'crm') {
         // bcc
         if (isset($_POST['bcc'])) {
             update_option('fue_bcc', $_POST['bcc']);
         }
         // from/reply-to name
         if (isset($_POST['from_name'])) {
             update_option('fue_from_name', $_POST['from_name']);
         }
         // from/reply-to
         if (isset($_POST['from_email'])) {
             update_option('fue_from_email', $_POST['from_email']);
         }
         // daily summary emails
         if (isset($_POST['daily_emails'])) {
             update_option('fue_daily_emails', $_POST['daily_emails']);
         }
         if (isset($_POST['daily_emails_time_hour'])) {
             $previous_time = get_option('fue_daily_emails_time', '00:00 AM');
             $time = $_POST['daily_emails_time_hour'] . ':' . $_POST['daily_emails_time_minute'] . ' ' . $_POST['daily_emails_time_ampm'];
             if ($previous_time != $time) {
                 update_option('fue_daily_emails_time', $time);
                 Follow_Up_Emails::instance()->scheduler->reschedule_daily_summary_email();
             }
         }
         do_action('fue_settings_crm_save', $_POST);
     } elseif ($section == 'system') {
         // process importing request
         if (isset($_FILES['emails_file']) && is_uploaded_file($_FILES['emails_file']['tmp_name'])) {
             ini_set("auto_detect_line_endings", true);
             $fh = @fopen($_FILES['emails_file']['tmp_name'], 'r');
             $columns = array();
             $i = 0;
             while ($row = fgetcsv($fh)) {
                 $i++;
                 if ($i == 1) {
                     foreach ($row as $idx => $col) {
                         $columns[$idx] = $col;
                     }
                     continue;
                 }
                 $data = array();
                 foreach ($columns as $idx => $col) {
                     if ($col == 'email_type') {
                         $col = 'type';
                         // convert 'product' emails to 'storewide'
                         if (in_array($row[$idx], array('product', 'normal', 'generic'))) {
                             $row[$idx] = 'storewide';
                         }
                     } elseif ($col == 'status') {
                         if ($row[$idx] == -1) {
                             $row[$idx] = FUE_Email::STATUS_ARCHIVED;
                         } elseif ($row[$idx] == 0) {
                             $row[$idx] = FUE_Email::STATUS_INACTIVE;
                         } else {
                             $row[$idx] = FUE_Email::STATUS_ACTIVE;
                         }
                     }
                     $data[$col] = $row[$idx];
                 }
                 fue_create_email($data);
             }
             $imported = '&imported=1';
         }
         // restore settings file from backup
         if (isset($_FILES['settings_file']) && is_uploaded_file($_FILES['settings_file']['tmp_name'])) {
             ini_set("auto_detect_line_endings", true);
             $fh = @fopen($_FILES['settings_file']['tmp_name'], 'r');
             $i = 0;
             while ($row = fgetcsv($fh)) {
                 $i++;
                 if ($i == 1) {
                     continue;
                 }
                 update_option($row[0], $row[1]);
             }
             $imported = '&imported=1';
         }
         // api
         if (!empty($_POST['api_enabled'])) {
             update_option('fue_api_enabled', 'yes');
         } else {
             update_option('fue_api_enabled', 'no');
         }
         // usage data
         if (isset($_POST['disable_usage_data']) && $_POST['disable_usage_data'] == 1) {
             update_option('fue_disable_usage_data', 1);
         } else {
             delete_option('fue_disable_usage_data');
         }
         // email batches
         if (isset($_POST['email_batch_enabled']) && $_POST['email_batch_enabled'] == 1) {
             update_option('fue_email_batches', 1);
             update_option('fue_emails_per_batch', intval($_POST['emails_per_batch']));
             update_option('fue_batch_interval', intval($_POST['email_batch_interval']));
         } else {
             update_option('fue_email_batches', 0);
         }
         // disable logging
         if (isset($_POST['action_scheduler_disable_logging']) && $_POST['action_scheduler_disable_logging'] == 1) {
             update_option('fue_disable_action_scheduler_logging', 1);
         } else {
             update_option('fue_disable_action_scheduler_logging', 0);
         }
         // delete all action scheduler comments
         if (isset($_POST['action_scheduler_delete_logs']) && $_POST['action_scheduler_delete_logs'] == 1) {
             $comment_ids = $wpdb->get_col("SELECT comment_ID FROM {$wpdb->comments} WHERE comment_type = 'action_log'");
             if ($comment_ids) {
                 foreach ($comment_ids as $comment_id) {
                     wp_delete_comment($comment_id, true);
                 }
             }
         }
         do_action('fue_settings_system_save', $_POST);
     } else {
         do_action('fue_settings_save', $_POST);
     }
     wp_redirect("admin.php?page=followup-emails-settings&tab={$section}&settings_updated=1{$imported}");
     exit;
 }