/**
  * 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);
             }
         }
     }
 }
 /**
  * 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_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(base64_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 ot_list_item_view($name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '')
 {
     /* 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()));
     /* load the old filterable slider settings */
     if ('slider' == $type) {
         $settings = ot_slider_settings($name);
     }
     /* if no settings array load the filterable list item settings */
     if (empty($settings)) {
         $settings = ot_list_item_settings($name);
     }
     /* merge the two settings array */
     $settings = array_merge($required_setting, $settings);
     echo '
 <div class="option-tree-setting">
   <div class="open">' . (isset($list_item['title']) ? esc_attr($list_item['title']) : '') . '</div>
   <div class="button-section">
     <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button button left-item" title="' . __('Edit', 'option-tree') . '">
       <span class="icon ot-icon-pencil"></span>' . __('Edit', 'option-tree') . '
     </a>
     <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button button button-secondary light right-item" title="' . __('Delete', 'option-tree') . '">
       <span class="icon ot-icon-trash-o"></span>' . __('Delete', 'option-tree') . '
     </a>
   </div>
   <div class="option-tree-setting-body">';
     foreach ($settings as $field) {
         // Set field value
         $field_value = isset($list_item[$field['id']]) ? $list_item[$field['id']] : '';
         /* set default to standard value */
         if (isset($field['std'])) {
             $field_value = ot_filter_std_value($field_value, $field['std']);
         }
         // filter the title label and description
         if ($field['id'] == 'title') {
             // filter the label
             $field['label'] = apply_filters('ot_list_item_title_label', $field['label'], $name);
             // filter the description
             $field['desc'] = apply_filters('ot_list_item_title_desc', $field['desc'], $name);
         }
         /* make life easier */
         $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name;
         /* build the arguments array */
         $_args = array('type' => $field['type'], 'field_id' => $name . '_' . $field['id'] . '_' . $key, 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', 'field_value' => $field_value, 'field_desc' => isset($field['desc']) ? $field['desc'] : '', 'field_std' => isset($field['std']) ? $field['std'] : '', 'field_rows' => isset($field['rows']) ? $field['rows'] : 10, 'field_post_type' => isset($field['post_type']) && !empty($field['post_type']) ? $field['post_type'] : 'post', 'field_taxonomy' => isset($field['taxonomy']) && !empty($field['taxonomy']) ? $field['taxonomy'] : 'category', 'field_min_max_step' => isset($field['min_max_step']) && !empty($field['min_max_step']) ? $field['min_max_step'] : '0,100,1', 'field_class' => isset($field['class']) ? $field['class'] : '', 'field_condition' => isset($field['condition']) ? $field['condition'] : '', 'field_operator' => isset($field['operator']) ? $field['operator'] : 'and', 'field_choices' => isset($field['choices']) && !empty($field['choices']) ? $field['choices'] : array(), 'field_settings' => isset($field['settings']) && !empty($field['settings']) ? $field['settings'] : array(), 'post_id' => $post_id, 'get_option' => $get_option);
         $conditions = '';
         /* setup the conditions */
         if (isset($field['condition']) && !empty($field['condition'])) {
             /* doing magic on the conditions so they work in a list item */
             $conditionals = explode(',', $field['condition']);
             foreach ($conditionals as $condition) {
                 $parts = explode(':', $condition);
                 if (isset($parts[0])) {
                     $field['condition'] = str_replace($condition, $name . '_' . $parts[0] . '_' . $key . ':' . $parts[1], $field['condition']);
                 }
             }
             $conditions = ' data-condition="' . $field['condition'] . '"';
             $conditions .= isset($field['operator']) && in_array($field['operator'], array('and', 'AND', 'or', 'OR')) ? ' data-operator="' . $field['operator'] . '"' : '';
         }
         /* option label */
         echo '<div id="setting_' . $_args['field_id'] . '" class="format-settings"' . $conditions . '>';
         /* don't show title with textblocks */
         if ($_args['type'] != 'textblock' && !empty($field['label'])) {
             echo '<div class="format-setting-label">';
             echo '<h3 class="label">' . esc_attr($field['label']) . '</h3>';
             echo '</div>';
         }
         /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */
         if ($_args['type'] == 'textarea') {
             $_args['type'] = 'textarea-simple';
         }
         /* option body, list-item is not allowed inside another list-item */
         if ($_args['type'] !== 'list-item' && $_args['type'] !== 'slider') {
             echo ot_display_by_type($_args);
         }
         echo '</div>';
     }
     echo '</div>';
     echo '</div>';
 }
 /**
  * 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_list_item_view($name, $key, $list_item = array(), $post_id = 0, $get_option = '', $settings = array(), $type = '')
 {
     /* 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()));
     /* load the old filterable slider settings */
     if ('slider' == $type) {
         $settings = ot_slider_settings($name);
     }
     /* if no settings array load the filterable list item settings */
     if (empty($settings)) {
         $settings = ot_list_item_settings($name);
     }
     /* merge the two settings array */
     $settings = array_merge($required_setting, $settings);
     echo '
 <div class="option-tree-setting">
   <div class="open">' . (isset($list_item['title']) ? esc_attr($list_item['title']) : 'Item ' . ($key + 1)) . '</div>
   <div class="button-section">
     <a href="javascript:void(0);" class="option-tree-setting-edit option-tree-ui-button left-item" title="' . __('Edit', 'option-tree') . '">
       <span class="icon pencil">' . __('Edit', 'option-tree') . '</span>
     </a>
     <a href="javascript:void(0);" class="option-tree-setting-remove option-tree-ui-button right-item" title="' . __('Delete', 'option-tree') . '">
       <span class="icon trash-can">' . __('Delete', 'option-tree') . '</span>
     </a>
   </div>
   <div class="option-tree-setting-body">';
     foreach ($settings as $field) {
         // Set field value
         $field_value = isset($list_item[$field['id']]) ? $list_item[$field['id']] : '';
         /* set default to standard value */
         if (isset($field['std'])) {
             $field_value = ot_filter_std_value($field_value, $field['std']);
         }
         /* make life easier */
         $_field_name = $get_option ? $get_option . '[' . $name . ']' : $name;
         /* build the arguments array */
         $_args = array('type' => $field['type'], 'field_id' => $name . '_' . $field['id'] . '_' . $key, 'field_name' => $_field_name . '[' . $key . '][' . $field['id'] . ']', 'field_value' => $field_value, 'field_desc' => isset($field['desc']) ? $field['desc'] : '', 'field_std' => isset($field['std']) ? $field['std'] : '', 'field_rows' => isset($field['rows']) ? $field['rows'] : 10, 'field_post_type' => isset($field['post_type']) && !empty($field['post_type']) ? $field['post_type'] : 'post', 'field_taxonomy' => isset($field['taxonomy']) && !empty($field['taxonomy']) ? $field['taxonomy'] : 'category', 'field_class' => isset($field['class']) ? $field['class'] : '', 'field_choices' => isset($field['choices']) && !empty($field['choices']) ? $field['choices'] : array(), 'field_settings' => isset($field['settings']) && !empty($field['settings']) ? $field['settings'] : array(), 'post_id' => $post_id, 'get_option' => $get_option);
         /* option label */
         echo '<div class="format-settings">';
         /* don't show title with textblocks */
         if ($_args['type'] != 'textblock') {
             echo '<div class="format-setting-label">';
             echo '<h3 class="label">' . esc_attr($field['label']) . '</h3>';
             echo '</div>';
         }
         /* only allow simple textarea inside a list-item due to known DOM issues with wp_editor() */
         if ($_args['type'] == 'textarea') {
             $_args['type'] = 'textarea-simple';
         }
         /* option body, list-item is not allowed inside another list-item */
         if ($_args['type'] !== 'list-item' && $_args['type'] !== 'slider') {
             echo ot_display_by_type($_args);
         }
         echo '</div>';
     }
     echo '</div>
 </div>';
 }