Пример #1
0
/**
 * Update an existing FUE_Email
 *
 * The ID of the email to update must be passed to the $args parameter.
 * The rest of the keys are similar to @see fue_create_email(). Only pass
 * the data that needs updating.
 *
 * @param array $args
 * @return int|WP_Error Returns the email ID on success, WP_Error on error
 */
function fue_update_email($args)
{
    if (isset($args['id'])) {
        $args['ID'] = $args['id'];
    }
    if (!isset($args['ID']) || empty($args['ID'])) {
        return new WP_Error('update_email', __('Cannot update email without the ID', 'follow_up_email'));
    }
    return fue_save_email($args);
}
Пример #2
0
 /**
  * Update the priorities the emails are loaded and displayed
  */
 public static function update_priorities()
 {
     $types = Follow_Up_Emails::get_email_types();
     foreach ($types as $key => $type) {
         if (isset($_POST[$key . '_order']) && !empty($_POST[$key . '_order'])) {
             foreach ($_POST[$key . '_order'] as $idx => $email_id) {
                 $priority = $idx + 1;
                 fue_save_email(array('id' => $email_id, 'priority' => $priority));
             }
         }
     }
     if (isset($_POST['bcc'])) {
         update_option('fue_bcc_types', $_POST['bcc']);
     }
     if (isset($_POST['from_email'])) {
         update_option('fue_from_email_types', $_POST['from_email']);
     }
     do_action('fue_update_priorities', $_POST);
 }
Пример #3
0
 /**
  * Process the data posted when saving the email
  */
 public function save_email($post_id, $post)
 {
     // $post_id and $post are required
     if (empty($post_id) || empty($post)) {
         return;
     }
     // Dont' save meta boxes for revisions or autosaves
     if (defined('DOING_AUTOSAVE') || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
         return;
     }
     // Check the post being saved == the $post_id to prevent triggering this call for other save_post events
     if (empty($_POST['post_ID']) || $_POST['post_ID'] != $post_id) {
         return;
     }
     if ($post->post_type != 'follow_up_email') {
         return;
     }
     $status = $_POST['post_status'];
     if ($status == 'draft') {
         $status = FUE_Email::STATUS_INACTIVE;
     } elseif ($status == 'publish') {
         $status = FUE_Email::STATUS_ACTIVE;
     }
     $conditions = array();
     if (!empty($_POST['conditions'])) {
         foreach ($_POST['conditions'] as $idx => $condition) {
             if ($idx === '_idx_') {
                 continue;
             }
             $conditions[$idx] = $condition;
         }
     }
     $data = apply_filters('fue_save_email_data', array('type' => $_POST['email_type'], 'status' => $status, 'ID' => $post_id, 'template' => $_POST['template'], 'meta' => $_POST['meta'], 'product_id' => !empty($_POST['product_id']) ? $_POST['product_id'] : 0, 'category_id' => !empty($_POST['category_id']) ? $_POST['category_id'] : 0, 'interval_num' => !empty($_POST['interval']) ? $_POST['interval'] : 1, 'interval_duration' => !empty($_POST['interval_duration']) ? $_POST['interval_duration'] : '', 'interval_type' => !empty($_POST['interval_type']) ? $_POST['interval_type'] : '', 'send_date' => !empty($_POST['send_date']) ? $_POST['send_date'] : '', 'send_date_hour' => !empty($_POST['send_date_hour']) ? $_POST['send_date_hour'] : '', 'always_send' => !empty($_POST['always_send']) ? $_POST['always_send'] : '', 'tracking_on' => !empty($_POST['tracking_on']) ? $_POST['tracking_on'] : 0, 'tracking' => !empty($_POST['tracking']) ? $_POST['tracking'] : '', 'coupon_id' => !empty($_POST['coupon_id']) ? $_POST['coupon_id'] : '', 'conditions' => !empty($conditions) ? $conditions : ''), $post_id, $post);
     // unhook this function so it doesn't loop infinitely
     remove_action('save_post', array($this, 'save_email'), 1);
     fue_save_email($data);
     add_action('save_post', array($this, 'save_email'), 1, 2);
     do_action('fue_after_save_email', $data);
 }