function ot_import() { /* check and verify import xml nonce */ if (isset($_POST['import_xml_nonce']) && wp_verify_nonce($_POST['import_xml_nonce'], 'import_xml_form')) { /* import input value */ $file = isset($_POST['import_xml']) ? esc_url($_POST['import_xml']) : ''; /* validate xml file */ if (preg_match("/(.xml)\$/i", $file) && class_exists('SimpleXMLElement')) { $settings = ot_import_xml($file); } /* default message */ $message = 'failed'; /* cleanup, save, & show success message */ if (isset($settings) && !empty($settings)) { /* delete file */ if ($file) { global $wpdb; $attachmentid = $wpdb->get_var("SELECT ID FROM {$wpdb->posts} WHERE guid='{$file}'"); wp_delete_attachment($attachmentid, true); } /* update settings */ update_option(ot_settings_id(), $settings); /* set message */ $message = 'success'; } /* redirect */ wp_redirect(add_query_arg(array('action' => 'import-xml', 'message' => $message), $_POST['_wp_http_referer'])); exit; } /* check and verify import settings nonce */ if (isset($_POST['import_settings_nonce']) && wp_verify_nonce($_POST['import_settings_nonce'], 'import_settings_form')) { /* textarea value */ $textarea = isset($_POST['import_settings']) ? unserialize(ot_decode($_POST['import_settings'])) : ''; /* default message */ $message = 'failed'; /* is array: save & show success message */ if (is_array($textarea)) { update_option(ot_settings_id(), $textarea); $message = 'success'; } /* redirect */ wp_redirect(add_query_arg(array('action' => 'import-settings', 'message' => $message), $_POST['_wp_http_referer'])); exit; } /* check and verify import theme options data nonce */ if (isset($_POST['import_data_nonce']) && wp_verify_nonce($_POST['import_data_nonce'], 'import_data_form')) { /* default message */ $message = 'failed'; /* textarea value */ $options = isset($_POST['import_data']) ? unserialize(ot_decode($_POST['import_data'])) : ''; /* get settings array */ $settings = get_option(ot_settings_id()); /* has options */ if (is_array($options)) { /* validate options */ if (is_array($settings)) { foreach ($settings['settings'] as $setting) { if (isset($options[$setting['id']])) { $content = ot_stripslashes($options[$setting['id']]); $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']); } } } /* execute the action hook and pass the theme options to it */ do_action('ot_before_theme_options_save', $options); /* update the option tree array */ update_option(ot_options_id(), $options); $message = 'success'; } /* redirect accordingly */ wp_redirect(add_query_arg(array('action' => 'import-data', 'message' => $message), $_POST['_wp_http_referer'])); exit; } /* check and verify import layouts nonce */ if (isset($_POST['import_layouts_nonce']) && wp_verify_nonce($_POST['import_layouts_nonce'], 'import_layouts_form')) { /* default message */ $message = 'failed'; /* textarea value */ $layouts = isset($_POST['import_layouts']) ? unserialize(ot_decode($_POST['import_layouts'])) : ''; /* get settings array */ $settings = get_option(ot_settings_id()); /* has layouts */ if (is_array($layouts)) { /* validate options */ if (is_array($settings)) { foreach ($layouts as $key => $value) { if ($key == 'active_layout') { continue; } $options = unserialize(ot_decode($value)); foreach ($settings['settings'] as $setting) { if (isset($options[$setting['id']])) { $content = ot_stripslashes($options[$setting['id']]); $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']); } } $layouts[$key] = ot_encode(serialize($options)); } } /* update the option tree array */ if (isset($layouts['active_layout'])) { $new_options = unserialize(ot_decode($layouts[$layouts['active_layout']])); /* execute the action hook and pass the theme options to it */ do_action('ot_before_theme_options_save', $new_options); update_option(ot_options_id(), $new_options); } /* update the option tree layouts array */ update_option(ot_layouts_id(), $layouts); $message = 'success'; } /* redirect accordingly */ wp_redirect(add_query_arg(array('action' => 'import-layouts', 'message' => $message), $_POST['_wp_http_referer'])); exit; } return false; }
function compat_ot_import_from_files() { /* file path & name without extention */ $ot_xml = '/option-tree/theme-options.xml'; $ot_data = '/option-tree/theme-options.txt'; $ot_layout = '/option-tree/layouts.txt'; /* XML file path - child theme first then parent */ if (is_readable(get_stylesheet_directory() . $ot_xml)) { $xml_file = get_stylesheet_directory_uri() . $ot_xml; } else { if (is_readable(get_template_directory() . $ot_xml)) { $xml_file = get_template_directory_uri() . $ot_xml; } } /* Data file path - child theme first then parent */ if (is_readable(get_stylesheet_directory() . $ot_data)) { $data_file = get_stylesheet_directory_uri() . $ot_data; } else { if (is_readable(get_template_directory() . $ot_data)) { $data_file = get_template_directory_uri() . $ot_data; } } /* Layout file path - child theme first then parent */ if (is_readable(get_stylesheet_directory() . $ot_layout)) { $layout_file = get_stylesheet_directory_uri() . $ot_layout; } else { if (is_readable(get_template_directory() . $ot_layout)) { $layout_file = get_template_directory_uri() . $ot_layout; } } /* check for files */ $has_xml = isset($xml_file) ? true : false; $has_data = isset($data_file) ? true : false; $has_layout = isset($layout_file) ? true : false; /* auto import XML file */ if ($has_xml == true && !get_option('option_tree_settings') && class_exists('SimpleXMLElement')) { $settings = ot_import_xml($xml_file); if (isset($settings) && !empty($settings)) { update_option('option_tree_settings', $settings); } } /* auto import Data file */ if ($has_data == true && !get_option('option_tree')) { $get_data = wp_remote_get($data_file); if (is_wp_error($get_data)) { return false; } $rawdata = isset($get_data['body']) ? $get_data['body'] : ''; $options = unserialize(ot_decode($rawdata)); /* get settings array */ $settings = get_option('option_tree_settings'); /* has options */ if (is_array($options)) { /* validate options */ if (is_array($settings)) { foreach ($settings['settings'] as $setting) { if (isset($options[$setting['id']])) { $content = ot_stripslashes($options[$setting['id']]); $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']); } } } /* update the option tree array */ update_option('option_tree', $options); } } /* auto import Layout file */ if ($has_layout == true && !get_option('option_tree_layouts')) { $get_data = wp_remote_get($data_file); if (is_wp_error($get_data)) { return false; } $rawdata = isset($get_data['body']) ? $get_data['body'] : ''; $layouts = unserialize(ot_decode($rawdata)); /* get settings array */ $settings = get_option('option_tree_settings'); /* has layouts */ if (is_array($layouts)) { /* validate options */ if (is_array($settings)) { foreach ($layouts as $key => $value) { if ($key == 'active_layout') { continue; } $options = unserialize(ot_decode($value)); foreach ($settings['settings'] as $setting) { if (isset($options[$setting['id']])) { $content = ot_stripslashes($options[$setting['id']]); $options[$setting['id']] = ot_validate_setting($content, $setting['type'], $setting['id']); } } $layouts[$key] = ot_encode(serialize($options)); } } /* update the option tree array */ if (isset($layouts['active_layout'])) { update_option('option_tree', unserialize(ot_decode($layouts[$layouts['active_layout']]))); } /* update the option tree layouts array */ update_option('option_tree_layouts', $layouts); } } }