/** 
  * Saves the enabled icons.
  *
  * @since 1.0
  * @access private
  * @return void
  */
 private static function save_enabled_icons()
 {
     if (isset($_POST['fl-icons-nonce']) && wp_verify_nonce($_POST['fl-icons-nonce'], 'icons')) {
         // Make sure we have at least one enabled icon set.
         if (!isset($_POST['fl-enabled-icons']) && empty($_POST['fl-new-icon-set'])) {
             self::add_error(__("Error! You must have at least one icon set enabled.", 'fl-builder'));
             return;
         }
         $filesystem = FLBuilderUtils::get_filesystem();
         $enabled_icons = array();
         // Sanitize the enabled icons.
         if (isset($_POST['fl-enabled-icons']) && is_array($_POST['fl-enabled-icons'])) {
             $enabled_icons = array_map('sanitize_text_field', $_POST['fl-enabled-icons']);
         }
         // Update the enabled sets.
         self::update_enabled_icons($enabled_icons);
         // Delete a set?
         if (!empty($_POST['fl-delete-icon-set'])) {
             $sets = FLBuilderIcons::get_sets();
             $key = sanitize_text_field($_POST['fl-delete-icon-set']);
             $index = array_search($key, $enabled_icons);
             if (false !== $index) {
                 unset($enabled_icons[$index]);
             }
             if (isset($sets[$key])) {
                 $filesystem->rmdir($sets[$key]['path'], true);
                 FLBuilderIcons::remove_set($key);
             }
         }
         // Upload a new set?
         if (!empty($_POST['fl-new-icon-set'])) {
             $dir = FLBuilderModel::get_cache_dir('icons');
             $id = (int) $_POST['fl-new-icon-set'];
             $path = get_attached_file($id);
             $new_path = $dir['path'] . 'icon-' . time() . '/';
             $unzipped = unzip_file($path, $new_path);
             // Unzip failed.
             if (!$unzipped) {
                 self::add_error(__("Error! Could not unzip file.", 'fl-builder'));
                 return;
             }
             // Move files if unzipped into a subfolder.
             $files = $filesystem->dirlist($new_path);
             if (1 == count($files)) {
                 $values = array_values($files);
                 $subfolder_info = array_shift($values);
                 $subfolder = $new_path . $subfolder_info['name'] . '/';
                 if (file_exists($subfolder) && is_dir($subfolder)) {
                     $files = $filesystem->dirlist($subfolder);
                     if ($files) {
                         foreach ($files as $file) {
                             $filesystem->move($subfolder . $file['name'], $new_path . $file['name']);
                         }
                     }
                     $filesystem->rmdir($subfolder);
                 }
             }
             // Check for supported sets.
             $is_icomoon = file_exists($new_path . 'selection.json');
             $is_fontello = file_exists($new_path . 'config.json');
             // Show an error if we don't have a supported icon set.
             if (!$is_icomoon && !$is_fontello) {
                 $filesystem->rmdir($new_path, true);
                 self::add_error(__("Error! Please upload an icon set from either Icomoon or Fontello.", 'fl-builder'));
                 return;
             }
             // Enable the new set.
             if (is_array($enabled_icons)) {
                 $key = FLBuilderIcons::get_key_from_path($new_path);
                 $enabled_icons[] = $key;
             }
         }
         // Update the enabled sets again in case they have changed.
         self::update_enabled_icons($enabled_icons);
     }
 }