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, '', '' ); } ?>
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' => '', 'before_title' => '