/**
  * 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_save_settings()
 {
     /* check and verify import settings nonce */
     if (isset($_POST['option_tree_settings_nonce']) && wp_verify_nonce($_POST['option_tree_settings_nonce'], 'option_tree_settings_form')) {
         /* 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(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;
 }