/**
  * Set currently stored theme settings based on options.
  *
  * @since 2.3.0
  *
  * @param array $settings Optional current settings to be applied.
  */
 public function set_settings($settings = null)
 {
     // Apply settings passed into function
     if ($settings && is_array($settings)) {
         $this->settings = $settings;
         return;
     }
     // Or pull settings from DB
     $this->settings = get_option($this->get_option_id());
     // Do settings exist? If not, grab default values.
     // Only do this for the frontend.
     if (!$this->settings) {
         // Because frontend, we need to add sanitiziation
         if (!is_admin()) {
             themeblvd_add_sanitization();
         }
         // Construct array of default values pulled from
         // formatted options.
         $defaults = themeblvd_get_option_defaults($this->formatted_options);
         $this->settings = $defaults;
         add_option($this->get_option_id(), $defaults);
     }
     $this->settings = apply_filters('themeblvd_frontend_options', $this->settings);
 }
 /**
  * Validate Options.
  *
  * This runs after the submit/reset button has been clicked and
  * validates the inputs.
  *
  * @since 2.2.0
  *
  * @param array $input Input from submitted form
  * @return array $clean Sanitized options from submitted form
  */
 public function validate($input)
 {
     // Restore Defaults --
     // In the event that the user clicked the "Restore Defaults"
     // button, the options defined in the theme's options.php
     // file will be added to the option for the active theme.
     if (isset($_POST['reset'])) {
         add_settings_error($this->id, 'restore_defaults', __('Default options restored.', 'themeblvd'), 'error fade');
         return themeblvd_get_option_defaults($this->options);
     }
     // Update Settings --
     // Basically, we're just looping through the current options
     // registered in this set and sanitizing each value from the
     // $input before sending back the final $clean array.
     $clean = array();
     foreach ($this->options as $option) {
         // Skip if we don't have an ID or type.
         if (!isset($option['id']) || !isset($option['type'])) {
             continue;
         }
         // Make sure ID is formatted right.
         $id = preg_replace('/\\W/', '', strtolower($option['id']));
         // Set checkbox to false if it wasn't sent in the $_POST
         if ('checkbox' == $option['type'] && !isset($input[$id])) {
             $input[$id] = '0';
         }
         // Set each item in the multicheck to false if it wasn't sent in the $_POST
         if ('multicheck' == $option['type'] && !isset($input[$id]) && !empty($option['options'])) {
             foreach ($option['options'] as $key => $value) {
                 $input[$id][$key] = '0';
             }
         }
         // For a value to be submitted to database it must pass through a sanitization filter
         if (has_filter('themeblvd_sanitize_' . $option['type'])) {
             $clean[$id] = apply_filters('themeblvd_sanitize_' . $option['type'], $input[$id], $option);
         }
     }
     // Extend
     $clean = apply_filters('themeblvd_options_sanitize_' . $this->id, $clean, $input);
     // Add update message for page re-fresh
     if (!$this->sanitized) {
         // Avoid duplicates
         add_settings_error($this->id, 'save_options', __('Options saved.', 'themeblvd'), 'updated fade');
     }
     // We know sanitization has happenned at least
     // once at this point; so set to true.
     $this->sanitized = true;
     // Return sanitized options
     return $clean;
 }