/** * Check if a field is enabled/disabled by the slider theme * @param string $theme * @param string $field */ function fa_theme_field_enabled($theme, $field) { $theme = fa_get_theme($theme); if (!$theme) { return true; } if (isset($theme['theme_config']['fields'][$field])) { return (bool) $theme['theme_config']['fields'][$field]; } return true; }
/** * Updates the slider options * @param int $post_id * @param array $values */ public function update_option($post_id, $values) { if (!current_user_can('manage_options') && !current_user_can('edit_fa_items', $post_id)) { wp_die(__('You are not allowed to do this.', 'fapro'), __('Not allowed', 'fapro')); } // get the defaults; also sets the post ID in parent class $defaults = $this->get_option($post_id); // stores theme details $theme_details = array(); // iterate the defaults and check if variables are set foreach ($defaults as $key => $vals) { // iterate the group defaults foreach ($vals as $field => $default_value) { // if value isn't set in class defaults, skip it if (!isset($this->defaults[$key][$field])) { continue; } // get the details of the theme set as active if ('theme' == $key && 'active' == $field) { if (isset($values[$key][$field])) { $theme = $values[$key][$field]; $theme_details = fa_get_theme($theme); } } // process themes params if ('themes_params' == $key) { // Deprecaterd themes parameters processing if ($this->deprecated && is_array($this->deprecated)) { if (array_key_exists($field, $this->deprecated)) { foreach ($this->deprecated[$field] as $f => $v) { if (is_bool($v)) { $defaults[$key][$field][$f] = isset($values[$f]); continue; } if (isset($values[$f])) { $defaults[$key][$field][$f] = $values[$f]; } } continue; } } // end deprecated themes params processing foreach ($default_value as $f => $v) { if (is_numeric($v)) { if (isset($values[$key][$field][$f])) { $defaults[$key][$field][$f] = (int) $values[$key][$field][$f]; } continue; } if (is_bool($v)) { $defaults[$key][$field][$f] = isset($values[$key][$field][$f]) && $values[$key][$field][$f]; continue; } if (isset($values[$key][$field][$f])) { $defaults[$key][$field][$f] = $values[$key][$field][$f]; } } continue; } if (is_int($this->defaults[$key][$field])) { if (isset($values[$key][$field])) { $defaults[$key][$field] = (int) $values[$key][$field]; } continue; } if (is_bool($this->defaults[$key][$field])) { $defaults[$key][$field] = isset($values[$key][$field]) && $values[$key][$field]; continue; } if (isset($values[$key][$field])) { $defaults[$key][$field] = $values[$key][$field]; } } } // store the theme details in slider settings $defaults['theme']['details'] = $theme_details; /** * Action on slide settings save * * @param int $post_id - id of post being saved * @param array $defaults - the new options * @param arrat $value - the values passed to be saved */ do_action('fa-save-slider-options', $post_id, $defaults, $values); return parent::update_the_option($defaults); }