/**
  * Import posts or pages from a CSV file.
  *
  * ## OPTIONS
  *
  * <file>
  * : The name of the CSV file to import.
  *
  * [--charset=<charset>]
  * : Character set of the CSV file. Defaults to UTF-8.
  *
  */
 function import($args, $assoc_args)
 {
     if (isset($assoc_args['charset']) && $assoc_args['charset']) {
         add_filter('advanced_csv_importer_csv_format', function ($format) use($assoc_args) {
             $format['from_charset'] = strtoupper($assoc_args['charset']);
             return $format;
         });
     }
     $post_objects = Main::get_post_objects($args[0]);
     if (is_wp_error($post_objects)) {
         WP_CLI::error($post_objects->get_error_message());
     }
     $inserted_posts = Main::insert_posts($post_objects);
     $this->get_imported_data($inserted_posts);
 }
 /**
  * The form of the second step.
  *
  * @param  none
  * @return none
  */
 private function step2()
 {
     $file = wp_import_handle_upload();
     if (isset($file['error'])) {
         return new WP_Error('Error', esc_html($file['error']));
     } else {
         if (!file_exists($file['file'])) {
             return new WP_Error('Error', sprintf(__('The export file could not be found at <code>%s</code>. It is likely that this was caused by a permissions problem.', 'advanced-csv-importer'), esc_html($file['file'])));
         }
     }
     $csv_file = get_attached_file($file['id']);
     $post_objects = Main::get_post_objects($csv_file);
     if (is_wp_error($post_objects)) {
         echo '<p><strong>' . __('Failed to open file.', 'advanced-csv-importer') . '</strong></p>';
         wp_import_cleanup($file['id']);
         return $post_objects;
     } else {
         $inserted_posts = Main::insert_posts($post_objects);
         wp_import_cleanup($file['id']);
         return $inserted_posts;
     }
 }
 /**
  * @test
  */
 public function parser()
 {
     $data = \ACSV\Main::csv_parser(dirname(__FILE__) . '/_data/csv/escaping.csv');
     $this->assertTrue(is_array($data));
 }