<?php



function xroc_import_xml_ajax() 
{
	if(!is_admin()) die();
	
    global $wpdb; 

    if ( !defined('WP_LOAD_IMPORTERS') ) define('WP_LOAD_IMPORTERS', true);
  
    // Load Importer API
    require_once ABSPATH . 'wp-admin/includes/import.php';

    if ( ! class_exists( 'WP_Importer' ) ) {
        $class_wp_importer = ABSPATH . 'wp-admin/includes/class-wp-importer.php';

        if ( file_exists( $class_wp_importer ) )
        {
            require $class_wp_importer;
        }
    }

    if ( ! class_exists( 'WP_Import' ) ) {
        $class_wp_importer = OPTIONS_DIR."/libs/wordpress-importer.php";
        if ( file_exists( $class_wp_importer ) ){
            require $class_wp_importer;
        }
    }

    if ( class_exists( 'WP_Import' ) ) 
    { 
		
        $import_filepath = OPTIONS_DIR ."/libs/demo.xml" ; // Get the xml file from directory 

        if(isset($GLOBALS['xroc_demo_details'])){
			$import_filepath = OPTIONS_DIR.'/demos/'.$GLOBALS['xroc_demo_details']['dir_name'].'/'.$GLOBALS['xroc_demo_details']['xml_filename'];
		}
		
		include_once('xml_import.php');

		//ob_start();
        $GLOBALS['wp_import'] = new WP_Import();
        $GLOBALS['wp_import']->fetch_attachments = true;
        $GLOBALS['wp_import']->import($import_filepath);
		
        //$wp_import->check();
		//ob_get_clean();
    }
	
	//die(); // this is required to return a proper result
	return true;
	exit;
}
add_action( 'wp_ajax_xroc_import_xml', 'xroc_import_xml_ajax' );



?>
