Support » Plugin: WordPress Importer » 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)


    • 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.