Example #1
0
function wf_theme_import_demo_xml()
{
    $error = false;
    if (!defined('WP_LOAD_IMPORTERS')) {
        define('WP_LOAD_IMPORTERS', true);
    }
    require_once ABSPATH . 'wp-admin/includes/import.php';
    if (!class_exists('WP_Import')) {
        $class_wp_import = get_template_directory() . '/admin/wordpress-importer/wordpress-importer.php';
        if (file_exists($class_wp_import)) {
            require_once $class_wp_import;
        } else {
            $error = true;
        }
    }
    if ($error) {
        add_settings_error('wf-theme-import-demo', 'wf-theme-import-demo', __('Demo data import failed! Try importing manually trough Tools - Import.', WF_THEME_TEXTDOMAIN), 'error');
        return false;
    } else {
        if (!is_file(get_template_directory() . '/admin/demo-data.xml')) {
            add_settings_error('wf-theme-import-demo', 'wf-theme-import-demo', __('Demo data XML file is missing.', WF_THEME_TEXTDOMAIN), 'error');
            return false;
        } else {
            ob_start();
            $wp_import = new wp_import();
            $wp_import->fetch_attachments = true;
            $wp_import->import(get_template_directory() . '/admin/demo-data.xml');
            ob_end_clean();
        }
    }
    return true;
}
Example #2
0
 function installDummy()
 {
     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 = get_template_directory() . '/admin/dummy_content/wordpress-importer/wordpress-importer.php';
         if (file_exists($class_wp_import)) {
             require_once $class_wp_import;
         } else {
             $importer_error = true;
         }
     }
     if ($importer_error) {
         die("Import error! Please unninstall Wordpress importer plugin and try again");
     } else {
         if (!is_file(get_template_directory() . "/admin/dummy_content/dummy.xml")) {
             echo "The XML file containing the dummy content is not available or could not be read in <pre>" . get_template_directory() . "/admin/dummy_content/dummy.xml</pre>";
         } else {
             $wp_import = new wp_import();
             $wp_import->fetch_attachments = false;
             $wp_import->import(get_template_directory() . "/admin/dummy_content/dummy.xml");
             setMenus();
             zn_set_options();
             //setWidgets();
             update_option(THEMENAME . '_dummy', 1);
         }
     }
 }