/**
  * Process postdata
  *
  * @return void
  */
 public function process_postdata($postdata)
 {
     // Clean postdata
     $postdata = GW_GoPricing_Helper::clean_input($postdata, 'filtered', '', array('thousand-sep'));
     $postdata = GW_GoPricing_Helper::remove_input($postdata, 'action');
     $settings = get_option(self::$plugin_prefix . '_table_settings', $postdata);
     // Veriify and save data
     if (!empty($postdata)) {
         if (empty($settings) || !empty($settings) && $settings != $postdata) {
             $result = update_option(self::$plugin_prefix . '_table_settings', $postdata);
             if ($result === false) {
                 GW_GoPricing_AdminNotices::add('general_settings', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
             } else {
                 GW_GoPricing_AdminNotices::add('general_settings', 'success', __('General Settings has been successfully updated!', 'go_pricing_textdomain'));
             }
         } else {
             GW_GoPricing_AdminNotices::add('general_settings', 'success', __('General Settings has been successfully updated!', 'go_pricing_textdomain'));
         }
     } else {
         GW_GoPricing_AdminNotices::add('general_settings', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
     }
 }
Esempio n. 2
0
 /**
  * Do import
  *
  * @return bool
  */
 public function save_table($data)
 {
     if (empty($data['name'])) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Pricing "Table Name" is empty!', 'go_pricing_textdomain'), false);
     }
     if (empty($data['id'])) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Pricing "Table ID" is empty!', 'go_pricing_textdomain'), false);
     } elseif (strlen($data['id']) >= 1 && preg_match('/([^a-z0-9\\-_])+/', $data['id']) == 1) {
         GW_GoPricing_AdminNotices::add('main', 'error', __('Pricing "Table ID" can contain only lowercase letters, numbers, hyphens and underscores!', 'go_pricing_textdomain'), false);
     } else {
         $tables = GW_GoPricing_Data::get_tables();
         foreach ((array) $tables as $table_key => $table) {
             $table_ids[$table_key] = $table['id'];
         }
         if (!empty($data['postid']) && !empty($table_ids[$data['postid']])) {
             unset($table_ids[$data['postid']]);
         }
         if (in_array($data['id'], $table_ids)) {
             GW_GoPricing_AdminNotices::add('main', 'error', sprintf(__('Pricing table with an ID of "%s" already exists! It must be uniqe.', 'go_pricing_textdomain'), $data['id']), false);
         }
     }
     $notices = GW_GoPricing_AdminNotices::get('main', 'error');
     if (isset($data['col-data'])) {
         $col_data = GW_GoPricing_Helper::clean_input($data['col-data'], 'html');
     }
     $data = GW_GoPricing_Helper::clean_input($data);
     if (isset($col_data)) {
         $data['col-data'] = $col_data;
     }
     if (empty($notices)) {
         $data = GW_GoPricing_Helper::remove_input($data, array($_POST['action']));
         $postid = GW_GoPricing_Data::update_table($data);
         if ($postid !== false) {
             // Create table message
             if (empty($data['postid'])) {
                 GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('Pricing table has been successfully created!<br>Shortcode: </strong>[go_pricing id="%s"]<strong>', 'go_pricing_textdomain'), $data['id']));
             } else {
                 GW_GoPricing_AdminNotices::add('main', 'success', sprintf(__('Pricing table has been successfully updated!<br>Shortcode: </strong>[go_pricing id="%s"]<strong>', 'go_pricing_textdomain'), $data['id']));
             }
             return $postid;
         } else {
             GW_GoPricing_AdminNotices::add('main', 'error', __('Oops, something went wrong!', 'go_pricing_textdomain'));
         }
     } else {
         $this->set_temp_postdata($data);
     }
     return false;
 }