response ) AND isset( $update_themes->response[ US_THEMENAME ] ) ) { $update_notification = sprintf( __( 'Some of demo data may be imported incorrectly, because you are using outdated %s version. %sUpdate the theme%s to import demos without possible issues.', 'us' ), US_THEMENAME, '', '' ); } ?>

$import ) { ?>

your site or start customize via Theme Options.', 'us' ), site_url(), admin_url( 'admin.php?page=us-theme-options' ) ) ?>

Activate the theme to unlock Demo Import', 'us' ), admin_url( 'admin.php?page=us-home#activation' ) ) ?>
us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=all_content'; $file_path = $upload_dir['basedir'] . '/all_content.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { // Mega menu import filters and actions - START add_filter( 'wp_import_post_data_raw', 'us_demo_import_all_wp_import_post_data_raw' ); function us_demo_import_all_wp_import_post_data_raw( $post ) { global $us_demo_import_mega_menu_data; if ( $post['post_type'] != 'nav_menu_item' ) { return $post; } if ( isset( $post['postmeta'] ) AND is_array( $post['postmeta'] ) ) { foreach ( $post['postmeta'] as $postmeta ) { if ( is_array( $postmeta ) AND isset( $postmeta['key'] ) AND $postmeta['key'] == 'us_mega_menu_settings' AND ! empty( $postmeta['value'] ) ) { if ( ! isset( $us_demo_import_mega_menu_data ) OR ! is_array( $us_demo_import_mega_menu_data ) ) { $us_demo_import_mega_menu_data = array(); } $us_demo_import_mega_menu_data[ intval( $post['post_id'] ) ] = $postmeta['value']; } } } return $post; } add_action( 'import_end', 'us_demo_import_all_import_end' ); function us_demo_import_all_import_end() { global $wp_import, $us_demo_import_mega_menu_data; if ( is_array( $us_demo_import_mega_menu_data ) ) { foreach ( $us_demo_import_mega_menu_data as $menu_import_id => $mega_menu_data ) { if ( ! empty( $wp_import->processed_menu_items[ $menu_import_id ] ) ) { update_post_meta( intval( $wp_import->processed_menu_items[ $menu_import_id ] ), 'us_mega_menu_settings', maybe_unserialize( $mega_menu_data ) ); } } } } // Mega menu import filters and actions - END us_demo_import_content( $file_path ); unlink( $file_path ); // Set menu if ( isset( $config[ $demo_version ]['nav_menu_locations'] ) ) { $locations = get_theme_mod( 'nav_menu_locations' ); $menus = array(); foreach ( wp_get_nav_menus() as $menu ) { if ( is_object( $menu ) ) { $menus[ $menu->name ] = $menu->term_id; } } foreach ( $config[ $demo_version ]['nav_menu_locations'] as $nav_location_key => $menu_name ) { if ( isset( $menus[ $menu_name ] ) ) { $locations[ $nav_location_key ] = $menus[ $menu_name ]; } } set_theme_mod( 'nav_menu_locations', $locations ); } // Set Front Page if ( isset( $config[ $demo_version ]['front_page'] ) ) { $front_page = get_posts( array( 'name' => $config[ $demo_version ]['front_page'], 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => 1, ) ); if ( $front_page ) { $front_page = $front_page[0]; } if ( isset( $front_page->ID ) ) { update_option( 'show_on_front', 'page' ); update_option( 'page_on_front', $front_page->ID ); } } // Trashing Hello World Post wp_trash_post( 1 ); if ( function_exists( 'wc_delete_product_transients' ) ) { wc_delete_product_transients(); } wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), us_translate( 'All content' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Pages add_action( 'wp_ajax_us_demo_import_content_pages', 'us_demo_import_content_pages' ); function us_demo_import_content_pages() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=pages'; $file_path = $upload_dir['basedir'] . '/pages.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { us_demo_import_content( $file_path ); unlink( $file_path ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), us_translate( 'Pages' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Posts add_action( 'wp_ajax_us_demo_import_content_posts', 'us_demo_import_content_posts' ); function us_demo_import_content_posts() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=posts'; $file_path = $upload_dir['basedir'] . '/posts.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { us_demo_import_content( $file_path ); unlink( $file_path ); // Trashing Hello World Post wp_trash_post( 1 ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), us_translate( 'Posts' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Portfolio add_action( 'wp_ajax_us_demo_import_content_portfolio', 'us_demo_import_content_portfolio' ); function us_demo_import_content_portfolio() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=portfolio_items'; $file_path = $upload_dir['basedir'] . '/portfolio_items.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { us_demo_import_content( $file_path ); unlink( $file_path ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Portfolio', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Testimonials add_action( 'wp_ajax_us_demo_import_content_testimonials', 'us_demo_import_content_testimonials' ); function us_demo_import_content_testimonials() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=testimonials'; $file_path = $upload_dir['basedir'] . '/testimonials.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { us_demo_import_content( $file_path ); unlink( $file_path ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Testimonials', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Grid Layouts add_action( 'wp_ajax_us_demo_import_content_grid_layouts', 'us_demo_import_content_grid_layouts' ); function us_demo_import_content_grid_layouts() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=grid_layouts'; $file_path = $upload_dir['basedir'] . '/grid_layouts.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { us_demo_import_content( $file_path ); unlink( $file_path ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Grid Layouts', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Page Blocks add_action( 'wp_ajax_us_demo_import_content_page_blocks', 'us_demo_import_content_page_blocks' ); function us_demo_import_content_page_blocks() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=page_blocks'; $file_path = $upload_dir['basedir'] . '/page_blocks.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { us_demo_import_content( $file_path ); unlink( $file_path ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Page Blocks', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } function us_demo_import_content( $file ) { global $us_template_directory, $wp_import; set_time_limit( 0 ); if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) { define( 'WP_LOAD_IMPORTERS', TRUE ); } if ( ! class_exists( 'WP_Import' ) ) { require_once( $us_template_directory . '/framework/vendor/wordpress-importer/wordpress-importer.php' ); } $wp_import = new WP_Import(); $wp_import->fetch_attachments = TRUE; ob_start(); $wp_import->import( $file ); ob_end_clean(); // Replace images in _wpb_shortcodes_custom_css meta with placeholder global $wpdb; $placeholder = $wpdb->get_col( "SELECT guid FROM $wpdb->posts WHERE guid like '%us-placeholder-landscape%';" ); if ( is_array( $placeholder ) AND isset( $placeholder[0] ) ) { $placeholder = $placeholder[0]; } if ( ! empty( $placeholder ) ) { $wpdb_results = $wpdb->get_results( "SELECT p.ID, pm.meta_value, pm.meta_key FROM {$wpdb->postmeta} pm LEFT JOIN {$wpdb->posts} p ON p.ID = pm.post_id WHERE (pm.meta_key = '_wpb_shortcodes_custom_css' OR pm.meta_key = 'us_og_image') AND p.post_status = 'publish'" ); foreach ( $wpdb_results as $meta_result ) { if ( $meta_result->ID ) { if ( $meta_result->meta_key == 'us_og_image' ) { $new_meta_value = preg_replace( '/(https?:\/\/[^ ,;]+\.(?:png|jpg))/i', $placeholder, $meta_result->meta_value ); if ( $new_meta_value !== $meta_result->meta_value ) { update_post_meta( $meta_result->ID, 'us_og_image', $new_meta_value ); } } else { $new_meta_value = preg_replace( '/(https?:\/\/[^ ,;]+\.(?:png|jpg))/i', $placeholder, $meta_result->meta_value ); if ( $new_meta_value !== $meta_result->meta_value ) { update_post_meta( $meta_result->ID, '_wpb_shortcodes_custom_css', $new_meta_value ); } } } } } // Remove meta dublicates for _wpb_shortcodes_custom_css $delete_meta_dublicates_sql = "DELETE FROM {$wpdb->postmeta} WHERE meta_key IN ('_wpb_shortcodes_custom_css', 'us_og_image', 'us_grid_layout_ids') AND meta_id NOT IN ( SELECT * FROM ( SELECT MAX(meta_id) FROM {$wpdb->postmeta} WHERE meta_key IN ('_wpb_shortcodes_custom_css', 'us_og_image', 'us_grid_layout_ids') GROUP BY post_id, meta_key ) AS x )"; $wpdb->query( $delete_meta_dublicates_sql ); } // Widgets Import add_action( 'wp_ajax_us_demo_import_widgets', 'us_demo_import_widgets' ); function us_demo_import_widgets() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $us_template_directory, $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } if ( isset( $config[ $demo_version ]['sidebars'] ) ) { $widget_areas = get_option( 'us_widget_areas' ); if ( empty( $widget_areas ) ) { $widget_areas = array(); } $args = array( 'description' => __( 'Custom Sidebar', 'us' ), 'before_widget' => '
', 'after_widget' => '
', 'before_title' => '

', 'after_title' => '

', 'class' => 'us-custom-area', ); foreach ( $config[ $demo_version ]['sidebars'] as $id => $name ) { if ( ! isset( $widget_areas[ $id ] ) ) { $args['name'] = $name; $args['id'] = $id; register_sidebar( $args ); $widget_areas[ $id ] = $name; } } update_option( 'us_widget_areas', $widget_areas ); } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=widgets'; $file_path = $upload_dir['basedir'] . '/widgets.json'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { ob_start(); require_once( $us_template_directory . '/framework/vendor/widget-importer-exporter/import.php' ); us_wie_process_import_file( $file_path ); ob_end_clean(); unlink( $file_path ); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Widgets & Sidebars', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } wp_send_json_success(); } // WooCommerce Import add_action( 'wp_ajax_us_demo_import_woocommerce', 'us_demo_import_woocommerce' ); function us_demo_import_woocommerce() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $us_template_directory, $help_portal_api_url; $config = us_config( 'demo-import', array() ); set_time_limit( 0 ); if ( ! defined( 'WP_LOAD_IMPORTERS' ) ) { define( 'WP_LOAD_IMPORTERS', TRUE ); } //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=products'; $file_path = $upload_dir['basedir'] . '/products.xml'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { if ( ! class_exists( 'WP_Import' ) ) { require_once( $us_template_directory . '/framework/vendor/wordpress-importer/wordpress-importer.php' ); } $wp_import = new WP_Import(); $wp_import->fetch_attachments = TRUE; // Creating attributes taxonomies global $wpdb; $parser = new WXR_Parser(); $import_data = $parser->parse( $file_path ); if ( isset( $import_data['posts'] ) ) { $posts = $import_data['posts']; if ( $posts AND sizeof( $posts ) > 0 ) { foreach ( $posts as $post ) { if ( 'product' === $post['post_type'] ) { if ( ! empty( $post['terms'] ) ) { foreach ( $post['terms'] as $term ) { if ( strstr( $term['domain'], 'pa_' ) ) { if ( ! taxonomy_exists( $term['domain'] ) ) { $attribute_name = wc_sanitize_taxonomy_name( str_replace( 'pa_', '', $term['domain'] ) ); // Create the taxonomy if ( ! in_array( $attribute_name, wc_get_attribute_taxonomies() ) ) { $attribute = array( 'attribute_label' => $attribute_name, 'attribute_name' => $attribute_name, 'attribute_type' => 'select', 'attribute_orderby' => 'menu_order', 'attribute_public' => 0, ); $wpdb->insert( $wpdb->prefix . 'woocommerce_attribute_taxonomies', $attribute ); delete_transient( 'wc_attribute_taxonomies' ); } // Register the taxonomy now so that the import works! register_taxonomy( $term['domain'], apply_filters( 'woocommerce_taxonomy_objects_' . $term['domain'], array( 'product' ) ), apply_filters( 'woocommerce_taxonomy_args_' . $term['domain'], array( 'hierarchical' => TRUE, 'show_ui' => FALSE, 'query_var' => TRUE, 'rewrite' => FALSE, ) ) ); } } } } } } } } ob_start(); $wp_import->import( $file_path ); ob_end_clean(); // Set WooCommerce Pages $shop_page = get_page_by_title( 'Shop' ); if ( isset( $shop_page->ID ) ) { update_option( 'woocommerce_shop_page_id', $shop_page->ID ); } $cart_page = get_page_by_title( 'Cart' ); if ( isset( $cart_page->ID ) ) { update_option( 'woocommerce_cart_page_id', $cart_page->ID ); } $checkout_page = get_page_by_title( 'Checkout' ); if ( isset( $checkout_page->ID ) ) { update_option( 'woocommerce_checkout_page_id', $checkout_page->ID ); } $my_account_page = get_page_by_title( 'My Account' ); if ( isset( $my_account_page->ID ) ) { update_option( 'woocommerce_myaccount_page_id', $my_account_page->ID ); } unlink( $file_path ); if ( function_exists( 'wc_delete_product_transients' ) ) { wc_delete_product_transients(); } wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Shop Products', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Import Theme Options add_action( 'wp_ajax_us_demo_import_options', 'us_demo_import_options' ); function us_demo_import_options() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $upload_dir = wp_upload_dir(); $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=theme_options'; $file_path = $upload_dir['basedir'] . '/theme_options.json'; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { $updated_options = json_decode( file_get_contents( $file_path ), TRUE ); if ( ! is_array( $updated_options ) ) { // Wrong file configuration wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Theme Options', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } usof_save_options( $updated_options ); unlink( $file_path ); wp_send_json_success(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Theme Options', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } // Import Revolution Sliders add_action( 'wp_ajax_us_demo_import_sliders', 'us_demo_import_sliders' ); function us_demo_import_sliders() { if ( ! check_ajax_referer( 'us-demo-import-actions', 'security', FALSE ) ) { wp_send_json_error( array( 'message' => us_translate( 'An error has occurred. Please reload the page and try again.' ), ) ); } global $help_portal_api_url; $config = us_config( 'demo-import', array() ); //select which files to import $aviable_demos = array_keys( $config ); $demo_version = $aviable_demos[0]; if ( in_array( $_POST['demo'], $aviable_demos ) ) { $demo_version = $_POST['demo']; } $sliders = $config[ $demo_version ]['sliders']; if ( ! class_exists( 'RevSlider' ) OR ! ( count( $sliders ) > 0 ) ) { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Revolution Sliders', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } if ( count( $sliders ) > 0 ) { $upload_dir = wp_upload_dir(); foreach ( $sliders as $slider_filename ) { $file_url = $help_portal_api_url . '?demo=' . $demo_version . '&file=' . $slider_filename; $file_path = trailingslashit( $upload_dir['basedir'] ) . $slider_filename; $file_copied = FALSE; // Fetching file with cURL if ( function_exists( 'curl_init' ) ) { $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL, $file_url ); curl_setopt( $ch, CURLOPT_HEADER, 0 ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, TRUE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, FALSE ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $contents = curl_exec( $ch ); curl_close( $ch ); if ( strlen( $contents ) > 50 ) { $fp = fopen( $file_path, 'w' ); fwrite( $fp, $contents ); $file_copied = TRUE; } } // If something is wrong with cURL, trying to use copy function if ( ! $file_copied ) { if ( copy( $file_url, $file_path ) AND filesize( $file_path ) > 50 ) { $file_copied = TRUE; } } if ( $file_copied ) { ob_start(); $_FILES["import_file"]["tmp_name"] = $file_path; $slider = new RevSlider(); $response = $slider->importSliderFromPost(); unset( $slider ); unlink( $file_path ); ob_end_clean(); } else { wp_send_json( array( 'success' => FALSE, 'error_title' => sprintf( __( 'Failed to import %s', 'us' ), __( 'Revolution Sliders', 'us' ) ), 'error_description' => __( 'Wrong path to the file or it is missing.', 'us' ), ) ); } } } wp_send_json_success(); }