n the plugin page. if ( $this->plugin_page === $hook ) { wp_enqueue_script( 'jquery-ui-dialog' ); wp_enqueue_style( 'wp-jquery-ui-dialog' ); wp_enqueue_script( 'ocdi-main-js', PT_OCDI_URL . 'assets/js/main.js' , array( 'jquery', 'jquery-ui-dialog' ), PT_OCDI_VERSION ); // Get theme data. $theme = wp_get_theme(); wp_localize_script( 'ocdi-main-js', 'ocdi', array( 'ajax_url' => admin_url( 'admin-ajax.php' ), 'ajax_nonce' => wp_create_nonce( 'ocdi-ajax-verification' ), 'import_files' => $this->import_files, 'wp_customize_on' => apply_filters( 'pt-ocdi/enable_wp_customize_save_hooks', false ), 'import_popup' => apply_filters( 'pt-ocdi/enable_grid_layout_import_popup_confirmation', true ), 'theme_screenshot' => $theme->get_screenshot(), 'dashboard_link' => get_admin_url( null, 'admin.php?page=ohio_hub' ), 'texts' => array( 'missing_preview_image' => esc_html__( 'No preview image defined for this import.', 'ohio-importer' ), 'dialog_title' => esc_html__( 'Demo Import', 'ohio-importer' ), 'dialog_no' => esc_html__( 'Cancel', 'ohio-importer' ), 'dialog_close' => esc_html__( 'Close', 'ohio-importer' ), 'dialog_activate' => esc_html__( 'Activate', 'ohio-importer' ), 'dialog_yes' => esc_html__( 'Yes, import!', 'ohio-importer' ), 'install_globals' => esc_html__( 'Install Theme Settings', 'ohio-importer' ), ), 'dialog_options' => apply_filters( 'pt-ocdi/confirmation_dialog_options', [] ) ) ); wp_enqueue_style( 'ocdi-main-css', PT_OCDI_URL . 'assets/css/ohio-importer.css', [], PT_OCDI_VERSION ); } } public function check_purchase_code_ajax_callback() { Helpers::verify_ajax_call(); $code = $_POST['purchase_code'] ?? ''; $status = 'none'; /* $req = @file_get_contents( 'https://demo.clbthemes.com/check/' . $code ); if ( $req === 'OK' ) { $status = 'verified'; } */ if (strlen($code) > 0) { $request = wp_remote_get( 'https://demo.clbthemes.com/check/' . $code ); $response = wp_remote_retrieve_body( $request ); if ( 'OK' === $response ) { $status = 'verified'; } } wp_send_json( [ 'status' => $status ] ); die(); } /** * Main AJAX callback function for: * 1). prepare import files (uploaded or predefined via filters) * 2). execute 'before content import' actions (before import WP action) * 3). import content * 4). execute 'after content import' actions (before widget import WP action, widget import, customizer import, after import WP action) */ public function import_demo_data_ajax_callback() { $dbgtrace = false; // Set true to var_dump stacktrace import process $dbgtrace && print('1. Start ajax callback. '); // Try to update PHP memory limit (so that it does not run out of it). ini_set( 'memory_limit', apply_filters( 'pt-ocdi/import_memory_limit', '350M' ) ); $dbgtrace && print('2. After ini_set and before verify_ajax_call. '); // Verify if the AJAX call is valid (checks nonce and current_user_can). Helpers::verify_ajax_call(); // Is this a new AJAX call to continue the previous import? $use_existing_importer_data = $this->use_existing_importer_data(); if ( ! $use_existing_importer_data ) { $dbgtrace && print('3. Preparing import files. '); // Create a date and time string to use for demo and log file names. Helpers::set_demo_import_start_time(); // Define log file path. $this->log_file_path = Helpers::get_log_path(); // Get selected file index or set it to 0. $this->selected_index = empty( $_POST['selected'] ) ? 0 : absint( $_POST['selected'] ); /** * 1). Prepare import files. * Manually uploaded import files or predefined import files via filter: pt-ocdi/import_files */ if ( ! empty( $_FILES ) ) { // Using manual file uploads? // Get paths for the uploaded files. $this->selected_import_files = Helpers::process_uploaded_files( $_FILES, $this->log_file_path ); // Set the name of the import files, because we used the uploaded files. $this->import_files[ $this->selected_index ]['import_file_name'] = esc_html__( 'Manually uploaded files', 'ohio-importer' ); } elseif ( ! empty( $this->import_files[ $this->selected_index ] ) ) { // Use predefined import files from wp filter: pt-ocdi/import_files. $dbgtrace && print('3.1. Download import files. '); // Download the import files (content, widgets and customizer files). $this->selected_import_files = Helpers::download_import_files( $this->import_files[ $this->selected_index ], $_POST['type'] ); // Check Errors. if ( is_wp_error( $this->selected_import_files ) ) { // Write error to log file and send an AJAX response with the error. Helpers::log_error_and_send_ajax_response( $this->selected_import_files->get_error_message(), $this->log_file_path, esc_html__( 'Downloaded files', 'ohio-importer' ) ); } // Add this message to log file. $log_added = Helpers::append_to_file( sprintf( __( 'The import files for: %s were successfully downloaded!', 'ohio-importer' ), $this->import_files[ $this->selected_index ]['import_file_name'] ) . Helpers::import_file_info( $this->selected_import_files ), $this->log_file_path, esc_html__( 'Downloaded files' , 'ohio-importer' ) ); } else { // Send JSON Error response to the AJAX call. wp_send_json( esc_html__( 'No import files specified!', 'ohio-importer' ) ); } } $dbgtrace && print('4. Before import executed and set transient. '); // Save the initial import data as a transient, so other import parts (in new AJAX calls) can use that data. Helpers::set_ocdi_import_data_transient( $this->get_current_importer_data() ); if ( ! $this->before_import_executed ) { $this->before_import_executed = true; /** * 2). Execute the actions hooked to the 'pt-ocdi/before_content_import_execution' action: * * Default actions: * 1 - Before content import WP action (with priority 10). */ $dbgtrace && print('5. before_content_import_execution. '); do_action( 'pt-ocdi/before_content_import_execution', $this->selected_import_files, $this->import_files, $this->selected_index ); } $dbgtrace && print('6. Import content. '); /** * 3). Import content. * Returns any errors greater then the "warning" logger level, that will be displayed on front page. */ // // --- NEW CODE HERE // /** WordPress Import Administration 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( 'WXR_Parser' ) ) { require_once dirname( __FILE__ ) . '/../default_wp_parser/class-wxr-parser.php'; } if ( !class_exists( 'WXR_Parser_SimpleXML' ) ) { require_once dirname( __FILE__ ) . '/../default_wp_parser/class-wxr-parser-simplexml.php'; } if ( !class_exists( 'WXR_Parser_XML' ) ) { require_once dirname( __FILE__ ) . '/../default_wp_parser/class-wxr-parser-xml.php'; } if ( !class_exists( 'WXR_Parser_Regex' ) ) { require_once dirname( __FILE__ ) . '/../default_wp_parser/class-wxr-parser-regex.php'; } // Renamed to Ohio_WP_Import require_once dirname( __FILE__ ) . '/../default_wp_parser/class-wp-import.php'; $post_options = ( $_POST['options'] ) ? json_decode( str_replace( '\\"', '"', $_POST['options'] ), true ) : []; $native_parser = new \Ohio_WP_Import([ 'media' => !empty( $post_options['media'] ), 'posts' => !empty( $post_options['posts'] ), 'projects' => !empty( $post_options['projects'] ), 'products' => !empty( $post_options['products'] ), 'forms' => !empty( $post_options['forms'] ) ]); // $this->append_to_frontend_error_messages( $native_parser->import( $this->selected_import_files['content'] ) ); ob_start(); $native_parser->import( $this->selected_import_files['content'] ); error_log( ob_get_clean() ); // // --- / NEW CODE HERE // // $this->append_to_frontend_error_messages( $this->importer->import_content( $this->selected_import_files['content'] ) ); // and execute //$exc_file = $this->import_files[ $this->selected_index ]['import_execute_file']; //if ( $exc_file ) { // $this->frontend_error_messages .= $this->import_exec( $exc_file ); //} /** * 4). Execute the actions hooked to the 'pt-ocdi/after_content_import_execution' action: * * Default actions: * 1 - Before widgets import setup (with priority 10). * 2 - Import widgets (with priority 20). * 3 - Import Redux data (with priority 30). */ $dbgtrace && print('7. after_content_import_execution. '); do_action( 'pt-ocdi/after_content_import_execution', $this->selected_import_files, $this->import_files, $this->selected_index ); // Save the import data as a transient, so other import parts (in new AJAX calls) can use that data. Helpers::set_ocdi_import_data_transient( $this->get_current_importer_data() ); // Request the customizer import AJAX call. if ( ! empty( $this->selected_import_files['customizer'] ) ) { wp_send_json( array( 'status' => 'customizerAJAX' ) ); } // Request the after all import AJAX call. if ( false !== has_action( 'pt-ocdi/after_all_import_execution' ) ) { wp_send_json( array( 'status' => 'afterAllImportAJAX' ) ); } // Send a JSON response with final report. $this->final_response(); } public function import_exec( $import_file_path ) { // Try to update PHP memory limit (so that it does not run out of it). ini_set( 'memory_limit', apply_filters( 'pt-ocdi/import_memory_limit', '350M' ) ); if ( ! empty( $import_file_path ) ) { if ( @file_exists( $import_file_path ) ) { include( $import_file_path ); if ( class_exists( '\RevSliderSlider' ) && count( $ocdi_slides_to_revolution ) > 0 ) { $absolute_path = __FILE__; $path_to_file = explode( 'wp-content', $absolute_path ); $path_to_wp = $path_to_file[0]; require_once( $path_to_wp . '/wp-load.php' ); require_once( $path_to_wp . '/wp-includes/functions.php'); require_once( $path_to_wp . '/wp-admin/includes/file.php'); $slider = new \RevSliderSlider(); foreach($ocdi_slides_to_revolution as $filepath){ $slider->importSliderFromPost( true, true, $filepath ); } } include PT_OCDI_PATH . 'inc/OhioDefaultParams.php'; global $wpdb; foreach (array_merge( $ocdi_fields_static, $ocdi_fields_to_change ) as $field => $value) { if ( $wpdb->get_var( 'SELECT COUNT(*) FROM ' . $wpdb->prefix . 'options WHERE option_name = \'' . $field . '\'' ) == 0 ) { $wpdb->insert( $wpdb->prefix . 'options', array( 'option_value' => $value, 'option_name' => $field, 'autoload' => 'no' ), array( '%s', '%s', '%s' ) ); } else { $wpdb->update( $wpdb->prefix . 'options', array( 'option_value' => $value ), array( 'option_name' => $field ) ); } } } } } /** * AJAX callback for importing the customizer data. * This request has the wp_customize set to 'on', so that the customizer hooks can be called * (they can only be called with the $wp_customize instance). But if the $wp_customize is defined, * then the widgets do not import correctly, that's why the customizer import has its own AJAX call. */ public function import_customizer_data_ajax_callback() { // Verify if the AJAX call is valid (checks nonce and current_user_can). Helpers::verify_ajax_call(); // Get existing import data. if ( $this->use_existing_importer_data() ) { /** * Execute the customizer import actions. * * Default actions: * 1 - Customizer import (with priority 10). */ do_action( 'pt-ocdi/customizer_import_execution', $this->selected_import_files ); } // Request the after all import AJAX call. if ( false !== has_action( 'pt-ocdi/after_all_import_execution' ) ) { wp_send_json( array( 'status' => 'afterAllImportAJAX' ) ); } // Send a JSON response with final report. $this->final_response(); } /** * AJAX callback for the after all import action. */ public function after_all_import_data_ajax_callback() { // Verify if the AJAX call is valid (checks nonce and current_user_can). Helpers::verify_ajax_call(); // Get existing import data. if ( $this->use_existing_importer_data() ) { /** * Execute the after all import actions. * * Default actions: * 1 - after_import action (with priority 10). */ do_action( 'pt-ocdi/after_all_import_execution', $this->selected_import_files, $this->import_files, $this->selected_index ); } // Send a JSON response with final report. $this->final_response(); } /** * Send a JSON response with final report. */ private function final_response() { // Delete importer data transient for current import. delete_transient( 'ocdi_importer_data' ); if (class_exists('OhioOptionsCache')) { \OhioOptionsCache::flush(); } // Display final messages (success or error messages). //if ( empty( $this->frontend_error_messages ) ) { $response['message'] = ''; $response['message'] .= sprintf( __( '%1$s%3$sThat\'s it, all done!%4$s%2$sThe demo import has finished. Please check the demo and make sure that everything has imported correctly.', 'ohio-importer' ), '
',
'
',
'',
'',
'
',
'
',
'',
'',
'',
'',
'