Title: WordPress-importer issue or wrong usage
Last modified: April 24, 2019

---

# WordPress-importer issue or wrong usage

 *  [Christophe Seguinot](https://wordpress.org/support/users/seguinot/)
 * (@seguinot)
 * [7 years, 1 month ago](https://wordpress.org/support/topic/wordpress-importer-issue-or-wrong-usage/)
 * Hi
 * I’m developping a theme. I wanted to programatically import some content using
   the WP_import class (wordpress-importer.php 0.6.4).
    At the beginning of my functions.
   php I define WP_LOAD_IMPORTERS constant (it must be defined for the class to 
   load).
 *     ```
       if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) {
           // define should be used outside class definition
           define( 'WP_LOAD_IMPORTERS', true );
       }
       ```
   
 * In my theme import class I’m loading WP_Import class with a code similar to this
   one.
 *     ```
       if ( ! class_exists( 'WP_Import' ) ) {
           $class_wp_import = ABSPATH . 'wp-content/plugins/wordpress-importer/wordpress-importer.php';
           if ( file_exists( $class_wp_import ) ) {
               require_once $class_wp_import;
           } else {
               // issue a message to tell the user to install wordpress-importer
           } 
       }
       ```
   
 * This works if and only if : wordpress-importer.php has been previously installed
   and is unactivated
 * When wordpress-importer.php is installed and activated I get different errors:
   -
   when using “require_once”:
    - wordpress-importer.php was previously loading and is not loading again
    - the WP_Import class was not loaded because WP_LOAD_IMPORTERS was not defined
      at the time of loading wordpress-importer.php
 * – when using “require” to load the WP_Import class:
    - I get the error reported in some other messages “Fatal error: Cannot redeclare
      wordpress_importer_init()”
 * This results from the fact that when WP_LOAD_IMPORTERS is not defined, the WP_Import
   class is not loaded, but the wordpress_importer_init() function is loaded.
 * Simple Workaround:
    - add “&import” to the admin page URL (in that case, WP_LOAD_IMPORTERS is defined
      in admin.php, line 31)
 * Questions:
    - Is there a proper/better way to load WP_Import class ?
    - Is this a wordpress-importer issue that can be solved be enclosing wordpress_importer_init()
      function inside and `if (!function_exists('wordpress_importer_init')) {...}`.
      In that case it could be possible to reload wordpress-importer.php.
 * Regards, Christophe

The topic ‘WordPress-importer issue or wrong usage’ is closed to new replies.

 * ![](https://ps.w.org/wordpress-importer/assets/icon.svg?rev=2791650)
 * [WordPress Importer](https://wordpress.org/plugins/wordpress-importer/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wordpress-importer/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wordpress-importer/)
 * [Active Topics](https://wordpress.org/support/plugin/wordpress-importer/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wordpress-importer/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wordpress-importer/reviews/)

## Tags

 * [standalone](https://wordpress.org/support/topic-tag/standalone/)

 * 0 replies
 * 1 participant
 * Last reply from: [Christophe Seguinot](https://wordpress.org/support/users/seguinot/)
 * Last activity: [7 years, 1 month ago](https://wordpress.org/support/topic/wordpress-importer-issue-or-wrong-usage/)
 * Status: not resolved