WP_Import::import_start PHP Method

import_start() public method

Parses the WXR file and prepares us for the task of processing parsed data
public import_start ( string $file )
$file string Path to the WXR file for importing
        function import_start($file)
        {
            if (!is_file($file)) {
                echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br />';
                echo __('The file does not exist, please try again.', 'wordpress-importer') . '</p>';
                $this->footer();
                die;
            }
            $import_data = $this->parse($file);
            if (is_wp_error($import_data)) {
                echo '<p><strong>' . __('Sorry, there has been an error.', 'wordpress-importer') . '</strong><br />';
                echo esc_html($import_data->get_error_message()) . '</p>';
                $this->footer();
                die;
            }
            $this->version = $import_data['version'];
            $this->get_authors_from_import($import_data);
            $this->posts = $import_data['posts'];
            $this->terms = $import_data['terms'];
            $this->categories = $import_data['categories'];
            $this->tags = $import_data['tags'];
            $this->base_url = esc_url($import_data['base_url']);
            wp_defer_term_counting(true);
            wp_defer_comment_counting(true);
            do_action('import_start');
        }

Usage Example

 public function get_importable_attachments($file)
 {
     $load_importer = $this->load_content_importer();
     if (!$load_importer) {
         return false;
     }
     $wp_import = new WP_Import();
     // this parse the file info
     $wp_import->import_start($file);
     $attachments = array();
     foreach ($wp_import->posts as $post) {
         if ($post['post_type'] == 'attachment') {
             $attachments[] = $post;
         }
     }
     return $attachments;
 }
All Usage Examples Of WP_Import::import_start