Exemplo n.º 1
0
 /**
  * Save the current popup to the database.
  *
  * @since  4.6
  * @param  bool $show_message If true then a success message will be
  *                displayed. Set to false when saving via ajax.
  */
 public function save($show_message = true)
 {
     global $allowedposttags;
     $this->validate_data();
     if (!did_action('wp_loaded')) {
         add_action('wp_loaded', array($this, 'save'));
         return false;
     }
     switch ($this->status) {
         case 'active':
             $status = 'publish';
             break;
         case 'inactive':
             $status = 'draft';
             break;
         case 'trash':
             $status = 'trash';
             break;
         default:
             $status = 'draft';
             break;
     }
     if ($status == 'publish') {
         // Limit the number of active PopUps.
         if (0 != IncPopupDatabase::count_active($this->id)) {
             IncPopupDatabase::deactivate_all();
             WDev()->message(sprintf(__('In the free version you can activate 1 PopUp. ' . 'The PRO Version allows you to have unlimited ' . 'active PopUps! ' . '<a href="%1$s" target="_blank">Find out more &raquo;</a>', PO_LANG), 'http://premium.wpmudev.org/project/the-pop-over-plugin/'));
         }
     }
     // When the content changed make sure to only allow valid code!
     if ($this->content != $this->orig_content && !current_user_can('unfiltered_html')) {
         $this->content = wp_kses($this->content, $allowedposttags);
     }
     // Check if the content contains (potentially) incompatible shortcodes.
     self::validate_shortcodes($this->content);
     $post = array('ID' => 0 == $this->id ? '' : $this->id, 'post_title' => $this->name, 'post_status' => $status, 'post_type' => self::POST_TYPE, 'post_content' => $this->content, 'menu_order' => $this->order);
     // Save the main popup item.
     $res = wp_insert_post($post);
     if (!empty($res)) {
         $this->id = $res;
         // Save metadata of the popup.
         update_post_meta($this->id, 'po_title', $this->title);
         update_post_meta($this->id, 'po_image', $this->image);
         update_post_meta($this->id, 'po_image_pos', $this->image_pos);
         update_post_meta($this->id, 'po_image_mobile', $this->image_mobile);
         update_post_meta($this->id, 'po_subtitle', $this->subtitle);
         update_post_meta($this->id, 'po_cta_label', $this->cta_label);
         update_post_meta($this->id, 'po_cta_link', $this->cta_link);
         update_post_meta($this->id, 'po_custom_size', $this->custom_size);
         update_post_meta($this->id, 'po_size', $this->size);
         update_post_meta($this->id, 'po_color', $this->color);
         update_post_meta($this->id, 'po_custom_colors', $this->custom_colors);
         update_post_meta($this->id, 'po_style', $this->style);
         update_post_meta($this->id, 'po_custom_css', $this->custom_css);
         update_post_meta($this->id, 'po_animation_in', $this->animation_in);
         update_post_meta($this->id, 'po_animation_out', $this->animation_out);
         update_post_meta($this->id, 'po_round_corners', $this->round_corners);
         update_post_meta($this->id, 'po_scroll_body', $this->scroll_body);
         update_post_meta($this->id, 'po_can_hide', $this->can_hide);
         update_post_meta($this->id, 'po_close_hides', $this->close_hides);
         update_post_meta($this->id, 'po_hide_expire', $this->hide_expire);
         update_post_meta($this->id, 'po_overlay_close', $this->overlay_close);
         update_post_meta($this->id, 'po_form_submit', $this->form_submit);
         update_post_meta($this->id, 'po_display', $this->display);
         update_post_meta($this->id, 'po_display_data', $this->display_data);
         update_post_meta($this->id, 'po_rule', $this->rule);
         update_post_meta($this->id, 'po_rule_files', $this->rule_files);
         update_post_meta($this->id, 'po_rule_data', $this->rule_data);
     }
     if ($show_message) {
         if (!empty($res)) {
             if ($this->orig_status === $this->status) {
                 $msg = __('Saved PopUp "<strong>%1$s</strong>"', PO_LANG);
             } else {
                 switch ($status) {
                     case 'publish':
                         $msg = __('Activated PopUp "<strong>%1$s</strong>".', PO_LANG);
                         break;
                     case 'draft':
                         $msg = __('Deactivated PopUp "<strong>%1$s</strong>".', PO_LANG);
                         break;
                     case 'trash':
                         $msg = __('Moved PopUp "<strong>%1$s</strong>" to trash.', PO_LANG);
                         break;
                     default:
                         $msg = __('Saved PopUp "<strong>%1$s</strong>".', PO_LANG);
                         break;
                 }
             }
             WDev()->message(sprintf($msg, $this->name));
         } else {
             WDev()->message(__('Could not save PopUp.', PO_LANG), 'err');
         }
     }
     return true;
 }