/** * Builds out the options panel. * * If we were using the Settings API as it was intended we would use * do_settings_sections here. But as we don't want the settings wrapped in a table, * we'll call our own custom hootoptions_fields. See hoot-options-interface.php * for specifics on how each individual field is generated. * * Nonces are provided using the settings_fields() * * @since 1.0.0 */ function options_page() { $name = Hoot_Options::_get_option_name(); ?> <div class="hootoptions-intro-box"> <div class="hootoptions-intro"> <a class="hootoptions-intro-img" href="<?php echo esc_url(THEME_AUTHOR_URI); ?> " /><img src="<?php echo trailingslashit(HOOT_IMAGES) . 'logo.png'; ?> "></a> <div class="hootoptions-intro-message"> <p><?php echo Hoot_Options_Interface::hootoptions_intro(); ?> </p> </div> </div> </div> <div id="hootoptions-wrap" class="hootoptions wrap"> <?php $menu = $this->menu_settings(); ?> <h2><?php echo esc_html($menu['page_title']); ?> </h2> <?php settings_errors('hoot-options'); ?> <h2 class="nav-tab-wrapper"> <?php echo Hoot_Options_Interface::hootoptions_tabs(); ?> </h2> <div id="hootoptions-box" class="metabox-holder"> <div id="hootoptions" class="postbox"> <form action="options.php" method="post"> <?php settings_fields($name); ?> <?php Hoot_Options_Interface::hootoptions_fields(); /* Settings */ ?> <div id="hootoptions-submit"> <input type="submit" class="button-primary" name="update" value="<?php esc_attr_e('Save Options', 'dispatch'); ?> " /> <input type="submit" class="reset-button button-secondary" name="reset" value="<?php esc_attr_e('Restore Defaults', 'dispatch'); ?> " onclick="return confirm( '<?php print esc_js(__('Click OK to reset. Any theme settings will be lost!', 'dispatch')); ?> ' );" /> <div class="clear"></div> </div> </form> </div> <!-- / #container --> </div> <?php do_action('hootoptions_after'); ?> </div> <!-- / .wrap --> <?php }
/** * 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>'; } }