/** * Upgrade * * All the functionality for upgrading XT Themes * * @since 1.0.0 */ function xt_upgrade() { global $XT_Theme, $wpdb, $wp_filesystem, $post; $xt_version_option_key = XT_THEME_ID . '_version'; $xt_theme = wp_get_theme(); $old_version = get_option($xt_version_option_key, '1.0.0'); // false $new_version = $XT_Theme->parent_version; if ($new_version !== $old_version) { /* * 1.0.4 * * @created 2015-02-21 */ if ($old_version < '1.0.4') { $xt_upload_dir = XT_Theme::get_upload_dir(); if (empty($wp_filesystem)) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } if ($wp_filesystem->is_dir($xt_upload_dir['dir'] . '/assets/')) { $wp_filesystem->delete($xt_upload_dir['dir'] . '/assets/', true, 'd'); $wp_filesystem->delete($xt_upload_dir['dir'] . '/bower_components/', true, 'd'); $wp_filesystem->delete($xt_upload_dir['dir'] . '/cache/', true, 'd'); } update_option($xt_version_option_key, '1.0.4'); } update_option($xt_version_option_key, $new_version); self::sass_compile_flag(); xt_redirect_after_migration(); } }
function import() { global $wpdb, $XT_Theme, $wp_filesystem; ob_start(); require_once XT_PARENT_DIR . '/lib/classes/autoimporter.class.php'; if (empty($wp_filesystem)) { require_once ABSPATH . '/wp-admin/includes/file.php'; WP_Filesystem(); } $upload_dir = XT_Theme::get_upload_dir(); $importPath = $upload_dir["dir"] . '/import/'; if (!$wp_filesystem->is_dir($importPath)) { wp_mkdir_p($importPath); } $placeholders = true; if (strpos($_SERVER['HTTP_HOST'], 'xplodedthemes') !== false || strpos($_SERVER['HTTP_HOST'], XT_THEME_ID . '.dev') !== false) { $placeholders = false; } $placeholders = true; $file = $importPath . 'default-data.xml'; $theme = !empty($_POST["theme"]) && $_POST["theme"] != 'default' ? '-' . sanitize_text_field($_POST["theme"]) : ''; $redux = !empty($_POST["redux"]) ? esc_url_raw($_POST["redux"]) : ''; $revslider = !empty($_POST["revslider"]) ? esc_url_raw($_POST["revslider"]) : ''; $widgets = !empty($_POST["widgets"]) ? esc_url_raw($_POST["widgets"]) : ''; $theme_child = !empty($_POST["theme"]) && $_POST["theme"] != 'default' ? sanitize_text_field($_POST["theme"]) . "\\/" : ''; $xml_import_url = XT_IMPORT_URL . '/default-data' . $theme . '.xml'; $file_content = xt_get_url_contents($xml_import_url); if (!empty($file_content) && $placeholders) { $file_content = preg_replace("/http:\\/\\/" . XT_THEME_ID . ".xplodedthemes\\.com\\/" . $theme_child . "wp-content\\/uploads\\/(.*?).(jpg|jpeg|png|gif)\\</", "http://placehold.it/400x400/f3f3f3/f3f3f3/placeholder.jpg<", $file_content); } if (empty($file_content)) { $message = 'Something went wrong! The theme was not able to fetch the default data xml from our server.<br><br>'; $message .= 'Please make sure your server support either <b>allow_url_open</b> or <b>cURL</b><br><br>'; $message .= 'You can also manually download the xml file and import it using WordPress Importer: <br><br><a target="_blank" href="' . $xml_import_url . '>Download XML Import File</a><br><br>'; $message .= '<b>Note:</b> Manually importing the xml will only include page and post contents excluding revolution sliders, widgets and theme panel settings.'; $data['error'] = true; $data['msg'] = '<p style="color: red;">' . $message . '</p>'; die(json_encode($data)); } if (!empty($file_content) && !$wp_filesystem->put_contents($file, $file_content, FS_CHMOD_FILE)) { $message = "Something went wrong! Don't worry, you have 2 different ways to fix it.<br><br>"; $message .= "<strong>Option 1)</strong> Make sure your WordPress uploads directory is writable<br>To do this, you need to set the folder permission to 777. Check this video to know how to set folder permission using FileZilla: <a href='http://www.youtube.com/watch?v=MKgfquaVAgM'>http://www.youtube.com/watch?v=MKgfquaVAgM</a><br><br>"; $message .= "<strong>Option 2)</strong> Import the default data using Wordpress Importer. Check our <a target='_blank' href='" . XT_DOCS_URL . "'>documentation</a> for more info"; $data['error'] = true; $data['msg'] = '<p style="color: red;">' . $message . '</p>'; die(json_encode($data)); } if (!empty($file_content) && @file_exists($file)) { /* Flush Data ========================================================================== */ $removed = array(); if ($wpdb->query("TRUNCATE TABLE {$wpdb->posts}")) { $removed[] = __('Posts removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->postmeta}")) { $removed[] = __('Postmeta removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->comments}")) { $removed[] = __('Comments removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->commentmeta}")) { $removed[] = __('Commentmeta removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->links}")) { $removed[] = __('Links removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->terms}")) { $removed[] = __('Terms removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->term_relationships}")) { $removed[] = __('Term relationships removed', XT_TEXT_DOMAIN); } if ($wpdb->query("TRUNCATE TABLE {$wpdb->term_taxonomy}")) { $removed[] = __('Term Taxonomy removed', XT_TEXT_DOMAIN); } if ($wpdb->query("DELETE FROM {$wpdb->options} WHERE `option_name` LIKE ('%_transient_%')")) { $removed[] = __('Transients removed', XT_TEXT_DOMAIN); } $wpdb->query("OPTIMIZE TABLE {$wpdb->options}"); foreach ($removed as $item) { $output[] = '' . $item . '<br>'; } $output[] = '<hr>'; /* Import XML ========================================================================== */ $args = array('file' => $file, 'map_user_id' => 1); auto_import($args); $output[] = '<p>' . __('Imported WordPress Content', XT_TEXT_DOMAIN) . '</p>'; /* Import Widgets ========================================================================== */ if (!empty($widgets)) { $widgets_options = xt_get_url_contents($widgets); if (!empty($widgets_options)) { $widgets_options = json_decode($widgets_options, true); foreach ($widgets_options as $option) { $key = $option["option_name"]; $value = unserialize($option["option_value"]); if ($key == 'widget_nav_menu' && !empty($value) && is_array($value)) { foreach ($value as $k => $v) { if (!empty($value[$k]['nav_menu'])) { $value[$k]['nav_menu'] = ''; } } } delete_option($key); add_option($key, $value); } } $output[] = '<p>' . __('Imported Widgets and assigned them to sidebars.', XT_TEXT_DOMAIN) . '</p>'; } /* Set Menu Location ========================================================================== */ if (!empty($XT_Theme->menus)) { $default_menu_id = 'main-menu'; $menu_id = (int) $wpdb->get_var($wpdb->prepare("SELECT term_id FROM {$wpdb->terms} WHERE slug = %s", $default_menu_id)); $locations = get_theme_mod('nav_menu_locations'); foreach ($XT_Theme->menus as $id => $menu) { $locations[$id] = $menu_id; } set_theme_mod('nav_menu_locations', $locations); $output[] = '<p>' . __('Imported Menus and assigned them to menu locations.', XT_TEXT_DOMAIN) . '</p>'; } /* Import Redux Settings ========================================================================== */ if (!empty($redux)) { $import = xt_get_url_contents($redux); if (!empty($import)) { $imported_options = json_decode($import, true); } if (!empty($imported_options) && is_array($imported_options) && isset($imported_options['redux-backup']) && $imported_options['redux-backup'] == '1') { unset($imported_options['defaults'], $imported_options['compiler'], $imported_options['import'], $imported_options['import_code']); update_option(XT_THEME_ID, $imported_options); $output[] = '<p>' . __('Imported Theme Options', XT_TEXT_DOMAIN) . '</p>'; } } /* Import Revolution Sliders ========================================================================== */ if (!empty($revslider) && function_exists('is_plugin_active') && is_plugin_active('revslider/revslider.php')) { $this->get_and_save($revslider); $output[] = '<p>' . __('Imported Revolution Sliders', XT_TEXT_DOMAIN) . '</p>'; } /* Import Essential Grid ========================================================================== */ if (!empty($essgrid) && function_exists('is_plugin_active') && is_plugin_active('essential-grid/essential-grid.php')) { $this->get_and_save($essgrid); $output[] = '<p>' . __('Imported Essential Grid Data', XT_TEXT_DOMAIN) . '</p>'; } flush_rewrite_rules(); $data['error'] = false; $data['msg'] = implode('', $output) . '<p style="color: green;"><strong>' . __('Import Succeeded!', XT_TEXT_DOMAIN) . '</strong></p>'; } else { $data['error'] = true; $data['msg'] = '<p style="color: red;"><strong>' . __('Import file is missing:', XT_TEXT_DOMAIN) . ' ' . $file . '</strong></p>'; } ob_end_clean(); die(json_encode($data)); }