WP_Import::import PHP Method

import() public method

The main controller for the actual import stage.
public import ( string $file )
$file string Path to the WXR file for importing
        function import($file)
        {
            add_filter('import_post_meta_key', array($this, 'is_valid_meta_key'));
            add_filter('http_request_timeout', array(&$this, 'bump_request_timeout'));
            $this->import_start($file);
            $this->get_author_mapping();
            wp_suspend_cache_invalidation(true);
            $this->process_categories();
            $this->process_tags();
            $this->process_terms();
            $this->process_posts();
            wp_suspend_cache_invalidation(false);
            // update incorrect/missing information in the DB
            $this->backfill_parents();
            $this->backfill_attachment_urls();
            $this->remap_featured_images();
            $this->import_end();
        }

Usage Example

Example #1
1
 public function set_demo_data($file)
 {
     if (!defined('WP_LOAD_IMPORTERS')) {
         define('WP_LOAD_IMPORTERS', true);
     }
     require_once ABSPATH . 'wp-admin/includes/import.php';
     $importer_error = false;
     if (!class_exists('WP_Importer')) {
         $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';
         if (file_exists($class_wp_importer)) {
             require_once $class_wp_importer;
         } else {
             $importer_error = true;
         }
     }
     if (!class_exists('WP_Import')) {
         $class_wp_import = dirname(__FILE__) . '/wordpress-importer.php';
         if (file_exists($class_wp_import)) {
             require_once $class_wp_import;
         } else {
             $importer_error = true;
         }
     }
     if ($importer_error) {
         die("Error on import");
     } else {
         if (!is_file($file)) {
             echo "The XML file containing the dummy content is not available or could not be read .. You might want to try to set the file permission to chmod 755.<br/>If this doesn't work please use the Wordpress importer and import the XML file (should be located in your download .zip: Sample Content folder) manually ";
         } else {
             $wp_import = new WP_Import();
             $wp_import->fetch_attachments = true;
             $wp_import->import($file);
         }
     }
 }
All Usage Examples Of WP_Import::import