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'; }
static function ot_theme_options() { if (!self::is_theme_installed()) { $theme_options_settings = BW_DEMO . 'theme-options-settings.txt'; if (file_exists($theme_options_settings)) { $theme_options_settings_content = file_get_contents($theme_options_settings); $default_option_tree = unserialize(ot_decode($theme_options_settings_content)); update_option('option_tree', $default_option_tree); } } }
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; } }
/** * Saves the meta box values * * @return void * * @access public * @since 1.0 */ function save_meta_box($post_id, $post_object) { global $pagenow; /* don't save during quick edit */ if ($pagenow == 'admin-ajax.php') { return $post_id; } /* don't save during autosave */ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return $post_id; } /* don't save if viewing a revision */ if ($post_object->post_type == 'revision') { return $post_id; } /* verify nonce */ if (isset($_POST[$this->meta_box['id'] . '_nonce']) && !wp_verify_nonce($_POST[$this->meta_box['id'] . '_nonce'], $this->meta_box['id'])) { return $post_id; } /* check permissions */ if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) { return $post_id; } } else { if (!current_user_can('edit_post', $post_id)) { return $post_id; } } foreach ($this->meta_box['fields'] as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = ''; /* there is data to validate */ if (isset($_POST[$field['id']])) { /* slider and list item */ if (in_array($field['type'], array('list-item', 'slider'))) { /* required title setting */ $required_setting = array(array('id' => 'title', 'label' => __('Title', 'option-tree'), 'desc' => '', 'std' => '', 'type' => 'text', 'rows' => '', 'class' => 'option-tree-setting-title', 'post_type' => '', 'choices' => array())); /* get the settings array */ $settings = isset($_POST[$field['id'] . '_settings_array']) ? unserialize(ot_decode($_POST[$field['id'] . '_settings_array'])) : array(); /* settings are empty for some odd ass reason get the defaults */ if (empty($settings)) { $settings = 'slider' == $field['type'] ? ot_slider_settings($field['id']) : ot_list_item_settings($field['id']); } /* merge the two settings array */ $settings = array_merge($required_setting, $settings); foreach ($_POST[$field['id']] as $k => $setting_array) { foreach ($settings as $sub_setting) { /* verify sub setting has a type & value */ if (isset($sub_setting['type']) && isset($_POST[$field['id']][$k][$sub_setting['id']])) { $_POST[$field['id']][$k][$sub_setting['id']] = ot_validate_setting($_POST[$field['id']][$k][$sub_setting['id']], $sub_setting['type'], $sub_setting['id']); } } } /* set up new data with validated data */ $new = $_POST[$field['id']]; } else { /* run through validattion */ $new = ot_validate_setting($_POST[$field['id']], $field['type'], $field['id']); } /* insert CSS */ if ($field['type'] == 'css') { /* insert CSS into dynamic.css */ if ('' !== $new) { ot_insert_css_with_markers($field['id'], $new, true); /* remove old CSS from dynamic.css */ } else { ot_remove_old_css($field['id']); } } } if ($new && $new !== $old) { update_post_meta($post_id, $field['id'], $new); } else { if ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } } } }
/** * AJAX utility function for adding a new list item. */ public function add_list_item() { ot_list_item_view($_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize(ot_decode($_REQUEST['settings'])), $_REQUEST['type']); die; }
/** * Sanitize callback for register_setting() * * @return string * * @access public * @since 2.0 */ public function sanitize_callback($input) { /* loop through options */ foreach ((array) $this->options as $option) { /* loop through pages */ foreach ((array) $this->get_pages($option) as $page) { /* loop through page settings */ foreach ((array) $this->get_the_settings($page) as $setting) { /* verify setting has a type & value */ if (isset($setting['type']) && isset($input[$setting['id']])) { /* get the defaults */ $current_settings = get_option('option_tree_settings'); $current_options = get_option($option['id']); /* validate setting */ if (is_array($input[$setting['id']]) && in_array($setting['type'], array('list-item', 'slider'))) { /* required title setting */ $required_setting = array(array('id' => 'title', 'label' => __('Title', 'option-tree'), 'desc' => '', 'std' => '', 'type' => 'text', 'rows' => '', 'class' => 'option-tree-setting-title', 'post_type' => '', 'choices' => array())); /* get the settings array */ $settings = isset($_POST[$setting['id'] . '_settings_array']) ? unserialize(ot_decode($_POST[$setting['id'] . '_settings_array'])) : array(); /* settings are empty for some odd ass reason get the defaults */ if (empty($settings)) { $settings = 'slider' == $setting['type'] ? ot_slider_settings($setting['id']) : ot_list_item_settings($setting['id']); } /* merge the two settings array */ $settings = array_merge($required_setting, $settings); /* create an empty WPML id array */ $wpml_ids = array(); foreach ($input[$setting['id']] as $k => $setting_array) { foreach ($settings as $sub_setting) { /* setup the WPML ID */ $wpml_id = $setting['id'] . '_' . $sub_setting['id'] . '_' . $k; /* add id to array */ $wpml_ids[] = $wpml_id; /* verify sub setting has a type & value */ if (isset($sub_setting['type']) && isset($input[$setting['id']][$k][$sub_setting['id']])) { /* validate setting */ $input[$setting['id']][$k][$sub_setting['id']] = ot_validate_setting($input[$setting['id']][$k][$sub_setting['id']], $sub_setting['type'], $sub_setting['id'], $wpml_id); } } } } else { $input[$setting['id']] = ot_validate_setting($input[$setting['id']], $setting['type'], $setting['id'], $setting['id']); } } /* unregister WPML strings that were deleted from lists and sliders */ if (isset($current_settings['settings']) && isset($setting['type']) && in_array($setting['type'], array('list-item', 'slider'))) { if (!isset($wpml_ids)) { $wpml_ids = array(); } foreach ($current_settings['settings'] as $check_setting) { if ($setting['id'] == $check_setting['id'] && !empty($current_options[$setting['id']])) { foreach ($current_options[$setting['id']] as $key => $value) { foreach ($value as $ckey => $cvalue) { $id = $setting['id'] . '_' . $ckey . '_' . $key; if (!in_array($id, $wpml_ids)) { ot_wpml_unregister_string($id); } } } } } } } } } return $input; }
function ot_modify_layouts() { /* check and verify modify layouts nonce */ if (isset($_POST['option_tree_modify_layouts_nonce']) && wp_verify_nonce($_POST['option_tree_modify_layouts_nonce'], 'option_tree_modify_layouts_form')) { /* previous layouts value */ $option_tree_layouts = get_option(ot_layouts_id()); /* new layouts value */ $layouts = isset($_POST[ot_layouts_id()]) ? $_POST[ot_layouts_id()] : ''; /* rebuild layout array */ $rebuild = array(); /* validate layouts */ if (is_array($layouts) && !empty($layouts)) { /* setup active layout */ if (isset($layouts['active_layout']) && !empty($layouts['active_layout'])) { $rebuild['active_layout'] = $layouts['active_layout']; } /* add new and overwrite active layout */ if (isset($layouts['_add_new_layout_']) && !empty($layouts['_add_new_layout_'])) { $rebuild['active_layout'] = ot_sanitize_layout_id($layouts['_add_new_layout_']); $rebuild[$rebuild['active_layout']] = ot_encode(serialize(get_option(ot_options_id()))); } $first_layout = ''; /* loop through layouts */ foreach ($layouts as $key => $layout) { /* skip over active layout key */ if ($key == 'active_layout') { continue; } /* check if the key exists then set value */ if (isset($option_tree_layouts[$key]) && !empty($option_tree_layouts[$key])) { $rebuild[$key] = $option_tree_layouts[$key]; if ('' == $first_layout) { $first_layout = $key; } } } if (isset($rebuild['active_layout']) && !isset($rebuild[$rebuild['active_layout']]) && !empty($first_layout)) { $rebuild['active_layout'] = $first_layout; } } /* default message */ $message = 'failed'; /* is array: save & show success message */ if (count($rebuild) > 1) { /* rebuild the theme options */ $rebuild_option_tree = unserialize(ot_decode($rebuild[$rebuild['active_layout']])); if (is_array($rebuild_option_tree)) { /* execute the action hook and pass the theme options to it */ do_action('ot_before_theme_options_save', $rebuild_option_tree); update_option(ot_options_id(), $rebuild_option_tree); } /* rebuild the layouts */ update_option(ot_layouts_id(), $rebuild); /* change message */ $message = 'success'; } else { if (count($rebuild) <= 1) { /* delete layouts option */ delete_option(ot_layouts_id()); /* change message */ $message = 'deleted'; } } /* redirect */ if (isset($_REQUEST['page']) && $_REQUEST['page'] == apply_filters('ot_theme_options_menu_slug', 'ot-theme-options')) { $query_args = add_query_arg(array('settings-updated' => 'layout'), remove_query_arg(array('action', 'message'), $_POST['_wp_http_referer'])); } else { $query_args = add_query_arg(array('action' => 'save-layouts', 'message' => $message), $_POST['_wp_http_referer']); } wp_redirect($query_args); 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); } } }
/** * AJAX utility function for adding a new social link. */ public function add_social_links() { check_ajax_referer('option_tree', 'nonce'); ot_social_links_view($_REQUEST['name'], $_REQUEST['count'], array(), $_REQUEST['post_id'], $_REQUEST['get_option'], unserialize(ot_decode($_REQUEST['settings'])), $_REQUEST['type']); die; }
function rj_taxonomy_ot_import_callback() { $plugins_url = plugins_url(); if (!isset($_POST['import_taxonomy_ot_meta_settings_nonce']) || !wp_verify_nonce($_POST['import_taxonomy_ot_meta_settings_nonce'], 'import_taxonomy_ot_meta_settings_form')) { $import_success = ''; } else { $ot_meta_settings = ot_decode($_REQUEST['import_taxonomy_ot_meta_settings']); $ot_meta_settings = unserialize($ot_meta_settings); update_option('rj_taxonomy_' . ot_settings_id(), $ot_meta_settings); $import_success = '<p style=" border: 1px solid #86B384; background: #A3C6A1; display: block; width: 62%; padding: 5px; color:#fff;">Imported Settings Successfully<p>'; } rj_ot_admin_styless(); echo '<form method="post" id="import_ot_meta_settings_form">'; echo '<h2>Import Taxonomy MetaboxUI Settings</h2>'; echo $import_success; /* form nonce */ wp_nonce_field('import_taxonomy_ot_meta_settings_form', 'import_taxonomy_ot_meta_settings_nonce'); /* format setting outer wrapper */ echo '<div class="format-setting type-textarea has-desc">'; /* description */ echo '<div class="description">'; echo '<p>' . __('To import your Settings copy and paste what appears to be a random string of alpha numeric characters into this textarea and press the "Import Settings" button.', 'option-tree') . '</p>'; echo '<p>' . __('Please note this will replace all of your current settings.', 'option-tree') . '</p>'; echo '</div>'; /* textarea */ echo '<div class="format-setting-inner">'; echo '<textarea rows="10" cols="40" name="import_taxonomy_ot_meta_settings" id="import_taxonomy_ot_meta_settings" class="textarea"></textarea>'; /* button */ echo '<button class="option-tree-ui-button button button-primary right hug-right">' . __('Import Settings', 'option-tree') . '</button>'; echo '</div>'; echo '</div>'; echo '</form>'; }
/** * Sanitize callback for register_setting() * * @return string * * @access public * @since 2.0 */ public function sanitize_callback($input) { /* loop through options */ foreach ((array) $this->options as $option) { /* loop through pages */ foreach ((array) $this->get_pages($option) as $page) { /* loop through page settings */ foreach ((array) $this->get_the_settings($page) as $setting) { /* verify setting has a type & value */ if (isset($setting['type']) && isset($input[$setting['id']])) { /* validate setting */ if (is_array($input[$setting['id']]) && in_array($setting['type'], array('list-item', 'slider'))) { /* required title setting */ $required_setting = array(array('id' => 'title', 'label' => __('Title', 'option-tree'), 'desc' => '', 'std' => '', 'type' => 'text', 'rows' => '', 'class' => 'option-tree-setting-title', 'post_type' => '', 'choices' => array())); /* get the settings array */ $settings = isset($_POST[$setting['id'] . '_settings_array']) ? unserialize(ot_decode($_POST[$setting['id'] . '_settings_array'])) : array(); /* settings are empty for some odd ass reason get the defaults */ if (empty($settings)) { $settings = 'slider' == $setting['type'] ? ot_slider_settings($setting['id']) : ot_list_item_settings($setting['id']); } /* merge the two settings array */ $settings = array_merge($required_setting, $settings); foreach ($input[$setting['id']] as $k => $setting_array) { foreach ($settings as $sub_setting) { /* verify sub setting has a type & value */ if (isset($sub_setting['type']) && isset($input[$setting['id']][$k][$sub_setting['id']])) { $input[$setting['id']][$k][$sub_setting['id']] = ot_validate_setting($input[$setting['id']][$k][$sub_setting['id']], $sub_setting['type'], $sub_setting['id']); } } } } else { $input[$setting['id']] = ot_validate_setting($input[$setting['id']], $setting['type'], $setting['id']); } } } } } return $input; }
function handle_ot_import($data) { if (!class_exists('OT_Loader')) { return new WP_Error('theme_options_ot_not_found', esc_html__('Option Tree is not installed, theme options not imported.', 'youxi')); } try { /* decode the theme options data */ $options = unserialize(ot_decode($data)); /* has options */ if (is_array($options)) { /* update the option tree options */ update_option(ot_options_id(), $options); } else { return new WP_Error('theme_options_invalid_data', esc_html__('The supplied theme options data is invalid.', 'youxi')); } } catch (Exception $e) { return new WP_Error('theme_options_unknown_error', $e->getMessage()); } return esc_html__('Theme options successfully imported.', 'youxi'); }