/** * Get the default values for all the theme options * * Get an array of all default values as set in * options.php. The 'id','std' and 'type' keys need * to be defined in the configuration array. In the * event that these keys are not present the option * will not be included in this function's output. * * @since 1.0.0 * @return array Re-keyed options configuration array. */ function get_default_values() { $output = array(); $config = Hoot_Options::_hootoptions_options(); foreach ((array) $config as $option) { if (!isset($option['id'])) { continue; } if (!isset($option['std'])) { continue; } if (!isset($option['type'])) { continue; } if (has_filter('hoot_of_sanitize_' . $option['type'])) { $output[$option['id']] = apply_filters('hoot_of_sanitize_' . $option['type'], $option['std'], $option); } } return $output; }
/** * Generates the options fields that are used in the form. * This function displays options using theme options page settings if $is_options_page is true, * else, it can render option fields for any $options array with $settings value (example: meta fields). * * @since 1.0.0 * @param bool $is_options_page If displaying options page * @param array $options Options array * @param array $settings Options values * @param string $prefix Options namespace */ static function hootoptions_fields($is_options_page = true, $options = array(), $settings = array(), $prefix = '') { $prefix = $prefix ? $prefix : THEME_SLUG; $counter = $subcounter = 0; /* If this is the options page then use theme options. */ if ($is_options_page === true) { $options = Hoot_Options::_hootoptions_options(); $option_name = Hoot_Options::_get_option_name(); $settings = self::$cache['settings'] = get_option($option_name); // For Settings API, the value array's name ($prefix) must be the same as // $option_name (as used in register_setting() ) $prefix = $option_name; } if (empty($options)) { return; } foreach ($options as $field) { if (!isset($field['type'])) { continue; /* Heading for Navigation */ } elseif ($field['type'] == 'heading') { if (!$is_options_page) { echo '<div class="section-header"><p>' . esc_html($field['name']) . '</p></div>' . "\n"; continue; } // (Options Page only) $output = ''; if ($subcounter) { $output .= '</div>' . "\n"; } $subcounter = 0; $counter++; if ($counter >= 2) { $output .= '</div>' . "\n"; } $class = $tab = ''; $class = $tab = !empty($field['id']) ? $field['id'] : $field['name']; $class = preg_replace('/[^a-zA-Z0-9._\\-]/', '', strtolower($class)); $output .= '<div id="tab-panel-' . $counter . '-panel" class="tab-panel ' . $class . '">'; // Add heading if this tab doesnt contain any subtabs if (!empty(self::$subtabs[$tab]) && is_array(self::$subtabs[$tab])) { $output .= '<div class="nav-subtab-wrapper">'; foreach (self::$subtabs[$tab] as $subkey => $subtab) { $stc = $counter . '_' . ($subkey + 1); $output .= '<div id="nav-subtab-' . $stc . '" class="nav-subtab" data-panel="' . esc_attr('#subtab-panel-' . $stc . '-panel') . '">' . esc_html($subtab) . '</div>'; } $output .= '</div>' . "\n"; } else { $output .= '<div class="nav-subtab-wrapper"><p>' . esc_html($field['name']) . '</p></div>' . "\n"; } echo $output; /* Subheadings for Navigation */ } elseif ($field['type'] == 'subheading') { if (!$is_options_page) { echo '<div class="section-header"><p>' . esc_html($field['name']) . '</p></div>' . "\n"; continue; } // (Options Page only) $output = ''; $subcounter++; if ($subcounter >= 2) { $output .= '</div>' . "\n"; } $class = ''; $class = !empty($field['id']) ? $field['id'] : $field['name']; $class = preg_replace('/[^a-zA-Z0-9_\\-]/', '', strtolower($class)); $output .= '<div id="subtab-panel-' . $counter . '_' . $subcounter . '-panel" class="subtab-panel ' . $class . '">'; echo $output; /* Raw HTML */ } elseif ($field['type'] == 'html') { if (isset($field['std'])) { } echo $field['std']; /* Other Field Types */ } else { $val = ''; // Set default value to $val if (isset($field['std'])) { $val = $field['std']; } // Set id for import/export if ($field['type'] == 'import') { $field['id'] = 'import'; } if ($field['type'] == 'export') { $field['id'] = 'export'; } // If the option is already saved, override $val if ($field['type'] != 'info') { if (isset($settings[$field['id']])) { $val = $settings[$field['id']]; // Striping slashes of non-array options and non-code options if (!is_array($val) && !($field['type'] == 'textarea' && !empty($field['settings']['code']))) { $val = stripslashes($val); } } } // Print the field HTML self::hootoptions_field($prefix, '', $field, $val, true); } } /* Outputs closing div if there subtabs in last tab (Options Page only) */ if ($is_options_page && $subcounter) { echo '</div>'; } /* Outputs closing div if there tabs (Options Page only) */ if ($is_options_page && Hoot_Options_Interface::hootoptions_tabs() != '') { echo '</div>'; } }