function thb_import_theme_options() { $file = get_template_directory_uri() . "/inc/democontent/theme-options.txt"; $theme_options_txt = wp_remote_get($file); $options = unserialize(ot_decode($theme_options_txt['body'])); /* get settings array */ $settings = get_option(ot_settings_id()); /* validate options */ 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(ot_options_id(), $options); $message = 'success'; }
function tm_import_themeoptions($data) { /* get settings array */ $settings = get_option('option_tree_settings'); /* validate options */ if (is_array($settings)) { foreach ($settings['settings'] as $setting) { if (isset($data[$setting['id']])) { $content = ot_stripslashes($data[$setting['id']]); $data[$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', $data); /* update the option tree array */ update_option('option_tree', $data); }
function ut_load_layout_into_ot($ot_layout_file) { $GLOBALS['ut_load_ot_layout'] = true; /* default file for theme activation */ $ot_layout_file = !empty($ot_layout_file) ? $ot_layout_file : 'default.txt'; /* needed option tree file for operatiob */ include_once THEME_DOCUMENT_ROOT . '/admin/includes/ot-functions-admin.php'; /* theme options file */ $ot_layout_file = get_template_directory() . '/admin/assets/optionsdata/' . $ot_layout_file; if (!is_readable($ot_layout_file)) { return; } /* file rawdata */ $rawdata = file_get_contents($ot_layout_file); $options = isset($rawdata) ? 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']); } } } /* end validate */ /* 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('option_tree', $options); update_option('ut_layout_loaded', 'active'); $GLOBALS['ut_load_ot_layout'] = false; } }
function ot_stripslashes($input) { if (is_array($input)) { foreach ($input as &$val) { if (is_array($val)) { $val = ot_stripslashes($val); } else { $val = stripslashes(trim($val)); } } } else { $input = stripslashes(trim($input)); } return $input; }
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); } } }
function rj_taxonomy_ot_save_settings() { if (isset($_REQUEST['page']) && $_REQUEST['page'] == 'rj-ot-taxonomy_metabox') { rj_ot_admin_scriptss(); rj_ot_admin_styless(); wp_enqueue_script('rj_ot_taxonomy_script', plugin_dir_url(dirname(__FILE__)) . 'js/taxonomy-ot-metabox-ui-settings.js'); } /* check and verify import settings nonce */ if (isset($_POST['option_tree_settings_nonce']) && wp_verify_nonce($_POST['option_tree_settings_nonce'], 'rj_option_tree_settings_form') && isset($_GET['page']) && $_GET['page'] == 'rj-ot-taxonomy_metabox') { /* settings value */ $settings = isset($_POST[ot_settings_id()]) ? $_POST[ot_settings_id()] : ''; /* validate sections */ if (isset($settings['sections'])) { /* fix numeric keys since drag & drop will change them */ $settings['sections'] = array_values($settings['sections']); /* loop through sections */ foreach ($settings['sections'] as $k => $section) { /* remove from array if missing values */ if (!isset($section['title']) && !isset($section['id']) || '' == $section['title'] && '' == $section['id']) { unset($settings['sections'][$k]); } else { /* validate label */ if ('' != $section['title']) { $settings['sections'][$k]['title'] = wp_kses_post($section['title']); } /* missing title set to unfiltered ID */ if (!isset($section['title']) || '' == $section['title']) { $settings['sections'][$k]['title'] = wp_kses_post($section['id']); /* missing ID set to title */ } else { if (!isset($section['id']) || '' == $section['id']) { $section['id'] = wp_kses_post($section['title']); } } /* sanitize ID once everything has been checked first */ $settings['sections'][$k]['id'] = ot_sanitize_option_id(wp_kses_post($section['id'])); } } $settings['sections'] = ot_stripslashes($settings['sections']); } /* validate settings by looping over array as many times as it takes */ if (isset($settings['settings'])) { $settings['settings'] = ot_validate_settings_array($settings['settings']); } /* validate contextual_help */ if (isset($settings['contextual_help']['content'])) { /* fix numeric keys since drag & drop will change them */ $settings['contextual_help']['content'] = array_values($settings['contextual_help']['content']); /* loop through content */ foreach ($settings['contextual_help']['content'] as $k => $content) { /* remove from array if missing values */ if (!isset($content['title']) && !isset($content['id']) || '' == $content['title'] && '' == $content['id']) { unset($settings['contextual_help']['content'][$k]); } else { /* validate label */ if ('' != $content['title']) { $settings['contextual_help']['content'][$k]['title'] = wp_kses_post($content['title']); } /* missing title set to unfiltered ID */ if (!isset($content['title']) || '' == $content['title']) { $settings['contextual_help']['content'][$k]['title'] = wp_kses_post($content['id']); /* missing ID set to title */ } else { if (!isset($content['id']) || '' == $content['id']) { $content['id'] = wp_kses_post($content['title']); } } /* sanitize ID once everything has been checked first */ $settings['contextual_help']['content'][$k]['id'] = ot_sanitize_option_id(wp_kses_post($content['id'])); } /* validate textarea description */ if (isset($content['content'])) { $settings['contextual_help']['content'][$k]['content'] = wp_kses_post($content['content']); } } } /* validate contextual_help sidebar */ if (isset($settings['contextual_help']['sidebar'])) { $settings['contextual_help']['sidebar'] = wp_kses_post($settings['contextual_help']['sidebar']); } $settings['contextual_help'] = ot_stripslashes($settings['contextual_help']); /* default message */ $message = 'failed'; /* is array: save & show success message */ if (is_array($settings)) { /* WPML unregister ID's that have been removed */ if (function_exists('icl_unregister_string')) { $current = get_option(ot_settings_id()); $options = get_option(ot_options_id()); if (isset($current['settings'])) { /* Empty ID array */ $new_ids = array(); /* Build the WPML IDs array */ foreach ($settings['settings'] as $setting) { if ($setting['id']) { $new_ids[] = $setting['id']; } } /* Remove missing IDs from WPML */ foreach ($current['settings'] as $current_setting) { if (!in_array($current_setting['id'], $new_ids)) { if (!empty($options[$current_setting['id']]) && in_array($current_setting['type'], array('list-item', 'slider'))) { foreach ($options[$current_setting['id']] as $key => $value) { foreach ($value as $ckey => $cvalue) { ot_wpml_unregister_string($current_setting['id'] . '_' . $ckey . '_' . $key); } } } else { if (!empty($options[$current_setting['id']]) && $current_setting['type'] == 'social-icons') { foreach ($options[$current_setting['id']] as $key => $value) { foreach ($value as $ckey => $cvalue) { ot_wpml_unregister_string($current_setting['id'] . '_' . $ckey . '_' . $key); } } } else { ot_wpml_unregister_string($current_setting['id']); } } } } } } update_option('rj_taxonomy_' . ot_settings_id(), $settings); $message = 'success'; } /* redirect */ wp_redirect(add_query_arg(array('action' => 'save-settings', 'message' => $message), $_POST['_wp_http_referer'])); exit; } return false; }
public function set_demo_theme_options($file) { $response = wp_remote_get(esc_url_raw($file)); /* Will result in $api_response being an array of data, parsed from the JSON response of the API listed above */ $data = wp_remote_retrieve_body($response); // Have valid data? // If no data or could not decode if (empty($data)) { wp_die(esc_html__('Theme options import data could not be read. Please try a different file.', 'radium'), '', array('back_link' => true)); } /* textarea value */ $options = unserialize(base64_decode($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']); } } } /* update the option tree array */ update_option(ot_options_id(), $options); /* execute the action hook and pass the theme options to it */ do_action('ot_after_theme_options_save', $options); } }