/**
  * Ajax import preset
  *
  * @since 4.0.0
  */
 function preset_import()
 {
     if (!empty($_POST) && array_key_exists('preset', $_POST) && array_key_exists('group', $_POST) && array_key_exists('_wpnonce', $_POST)) {
         $preset = $_POST['preset'];
         $group = $_POST['group'];
         $_wpnonce = $_POST['_wpnonce'];
         // generate query arg url
         $query_arg_url = $_SERVER['HTTP_REFERER'];
         $query_arg_url = add_query_arg(array('_group' => $group, '_preset' => $preset), $query_arg_url);
         $validate = check_ajax_referer('cherry_preset_import', $_wpnonce, false);
         if (!$validate) {
             wp_die(__('Invalid request', 'cherry'), __('Error. Invalid request', 'cherry'));
         }
         if (false !== self::get_preset_json($this->default_settings[$group]['presets'][$preset]['preset'])) {
             $file_name = self::get_preset_json($this->default_settings[$group]['presets'][$preset]['preset']);
             $file_content = self::get_contents($file_name);
             $file_content = !is_wp_error($file_content) ? $file_content : '{}';
             if ('string' !== gettype($file_content)) {
                 wp_send_json(array('type' => 'error', 'url' => $query_arg_url));
             }
             $import_options = json_decode($file_content, true);
             $import_statics = isset($import_options['statics']) ? $import_options['statics'] : array();
             $import_options = isset($import_options['options']) ? $import_options['options'] : $import_options;
             if (!is_array($import_options) || empty($import_options)) {
                 wp_send_json(array('type' => 'error', 'url' => $query_arg_url));
             }
             // get current options array
             $settings = get_option('cherry-options');
             $current_options = get_option($settings['id']);
             if (Cherry_Style_Switcher::is_demo_mode()) {
                 $current_options = isset($_SESSION['demo_options_storage']['options']) ? $_SESSION['demo_options_storage']['options'] : $_SESSION['demo_options_storage'];
             }
             $result = array();
             foreach ($current_options as $section => $data) {
                 foreach ($data['options-list'] as $opt => $val) {
                     if (isset($import_options[$opt])) {
                         $result[$section]['options-list'][$opt] = $import_options[$opt];
                     } else {
                         $result[$section]['options-list'][$opt] = $current_options[$section]['options-list'][$opt];
                     }
                 }
             }
             if (Cherry_Style_Switcher::is_demo_mode()) {
                 $_SESSION['demo_options_storage']['options'] = $result;
                 if (!empty($import_statics) && isset($import_statics)) {
                     $_SESSION['demo_options_storage']['statics'] = $import_statics;
                 }
                 wp_send_json(array('type' => 'success', 'url' => $query_arg_url));
             }
             update_option($settings['id'], $result);
             if (!empty($import_statics) && isset($import_statics)) {
                 update_option($settings['id'] . '_statics', $import_statics);
             }
         }
         wp_send_json(array('type' => 'success', 'url' => $query_arg_url));
     }
 }
 /**
  * Returns the instance.
  *
  * @since  1.0.0
  * @return object
  */
 public static function get_instance()
 {
     // If the single instance hasn't been set, set it now.
     if (null == self::$instance) {
         self::$instance = new self();
     }
     return self::$instance;
 }