Skip to content
Browse files

Re: Issue #72 implements support for Oenology settings in Theme Custo…

…mizer
  • Loading branch information...
1 parent 8bd4ebf commit 791d6a94e457ee9817bbce257ddda99cfb7f6248 @chipbennett committed May 4, 2012
Showing with 150 additions and 21 deletions.
  1. +9 −0 functions.php
  2. +120 −0 functions/options-customizer.php
  3. +0 −21 functions/options-register.php
  4. +21 −0 functions/options.php
View
9 functions.php
@@ -89,6 +89,15 @@
require( get_template_directory() . '/functions/options.php' );
/**
+ * Include the Theme Options Theme Customizer Function File
+ *
+ * options-customizer.php includes the functions required to
+ * integrate the Theme options into the WordPress Theme
+ * Customizer.
+ */
+require( get_template_directory() . '/functions/options-customizer.php' );
+
+/**
* Include the Theme Custom Hooks Function File
*
* hooks.php includes the Theme's custom hooks
View
120 functions/options-customizer.php
@@ -0,0 +1,120 @@
+<?php
+/**
+ * Oenology Options Theme Customizer Integration
+ *
+ * This file integrates the Theme Customizer
+ * for the Oenology Theme.
+ *
+ * @package Oenology
+ * @copyright Copyright (c) 2012, Chip Bennett
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU General Public License, v2 (or newer)
+ *
+ * @since Oenology 2.6
+ */
+
+/**
+ * Oenology Theme Settings Theme Customizer Implementation
+ *
+ * Implement the Theme Customizer for the
+ * Oenology Theme Settings.
+ *
+ * @param object $wp_customize Object that holds the customizer data
+ *
+ * @link http://ottopress.com/2012/how-to-leverage-the-theme-customizer-in-your-own-themes/ Otto
+ */
+function oenology_register_theme_customizer( $wp_customize ){
+
+ // Failsafe is safe
+ if ( ! isset( $wp_customize ) ) {
+ return;
+ }
+
+ global $oenology_options;
+ $oenology_options = oenology_get_options();
+
+ // Get the array of option parameters
+ $option_parameters = oenology_get_option_parameters();
+ // Get the array of option defaults
+ $option_defaults = oenology_get_option_defaults();
+ // Get list of tabs
+ $tabs = oenology_get_settings_page_tabs();
+
+ // Add Sections
+ foreach ( $tabs as $tab ) {
+ // Add $tab section
+ $wp_customize->add_section( 'oenology_' . $tab['name'], array(
+ 'title' => 'Oenology ' . $tab['title'] . ' Settings',
+ ) );
+ }
+
+ // Add Settings
+ foreach ( $option_parameters as $option_parameter ) {
+ // Add $option_parameter setting
+ $wp_customize->add_setting( 'theme_oenology_options[' . $option_parameter['name'] . ']', array(
+ 'default' => $oenology_options[$option_parameter['name']],
+ 'type' => 'option',
+ ) );
+
+ // Add $option_parameter control
+ if ( 'text' == $option_parameter['type'] ) {
+ $wp_customize->add_control( 'oenology_' . $option_parameter['name'], array(
+ 'label' => $option_parameter['title'],
+ 'section' => 'oenology_' . $option_parameter['tab'],
+ 'settings' => 'theme_oenology_options['. $option_parameter['name'] . ']',
+ 'type' => 'text',
+ ) );
+
+ } else if ( 'checkbox' == $option_parameter['type'] ) {
+ $wp_customize->add_control( 'oenology_' . $option_parameter['name'], array(
+ 'label' => $option_parameter['title'],
+ 'section' => 'oenology_' . $option_parameter['tab'],
+ 'settings' => 'theme_oenology_options['. $option_parameter['name'] . ']',
+ 'type' => 'checkbox',
+ ) );
+
+ } else if ( 'radio' == $option_parameter['type'] ) {
+ $valid_options = array();
+ foreach ( $option_parameter['valid_options'] as $valid_option ) {
+ $valid_options[$valid_option['name']] = $valid_option['title'];
+ }
+ $wp_customize->add_control( 'oenology_' . $option_parameter['name'], array(
+ 'label' => $option_parameter['title'],
+ 'section' => 'oenology_' . $option_parameter['tab'],
+ 'settings' => 'theme_oenology_options['. $option_parameter['name'] . ']',
+ 'type' => 'radio',
+ 'choices' => $valid_options,
+ ) );
+
+ } else if ( 'select' == $option_parameter['type'] ) {
+ $valid_options = array();
+ foreach ( $option_parameter['valid_options'] as $valid_option ) {
+ $valid_options[$valid_option['name']] = $valid_option['title'];
+ }
+ $wp_customize->add_control( 'oenology_' . $option_parameter['name'], array(
+ 'label' => $option_parameter['title'],
+ 'section' => 'oenology_' . $option_parameter['tab'],
+ 'settings' => 'theme_oenology_options['. $option_parameter['name'] . ']',
+ 'type' => 'select',
+ 'choices' => $valid_options,
+ ) );
+ } else if ( 'custom' == $option_parameter['type'] ) {
+ $valid_options = array();
+ foreach ( $option_parameter['valid_options'] as $valid_option ) {
+ $valid_options[$valid_option['name']] = $valid_option['title'];
+ }
+ $wp_customize->add_control( 'oenology_' . $option_parameter['name'], array(
+ 'label' => $option_parameter['title'],
+ 'section' => 'oenology_' . $option_parameter['tab'],
+ 'settings' => 'theme_oenology_options['. $option_parameter['name'] . ']',
+ 'type' => 'select',
+ 'choices' => $valid_options,
+ ) );
+ }
+ }
+
+}
+// Settings API options initilization and validation
+add_action( 'customize_register', 'oenology_register_theme_customizer' );
+
+
+?>
View
21 functions/options-register.php
@@ -206,27 +206,6 @@ function oenology_sections_callback( $section_passed ) {
}
/**
- * Add Section Text for the Varietal Settings Section
- */
-function oenology_get_varietal_text() {
-
- $oenology_options = oenology_get_options();
- $option_parameters = oenology_get_option_parameters();
- $oenology_varietals = $option_parameters['varietal']['valid_options'];
- foreach ( $oenology_varietals as $varietal ) {
- if ( $varietal['name'] == $oenology_options['varietal'] ) {
- $oenology_current_varietal = $varietal;
- }
- }
- $text = '';
- $text .= '<p>"Varietal" refers to wine made from exclusively or predominantly one variety of grape. Each varietal has unique flavor and aromatic characteristics. Refer to the contextual help screen for descriptions and help regarding each theme option.</p>';
- $text .= '<img class="oenology-varietal-thumb" src="' . get_template_directory_uri() . '/varietals/' . $oenology_options['varietal'] . '.png' . '" width="150px" height="110px" alt="' . $oenology_options['varietal'] . '" />';
- $text .= '<h4>Current Varietal</h4>';
- $text .= '<dl><dt><strong>' . $oenology_current_varietal['title'] . '</strong></dt><dd>' . $oenology_current_varietal['description'] . '</dd></dl>';
- return $text;
-}
-
-/**
* Globalize the variable that holds
* all the Theme option parameters
*
View
21 functions/options.php
@@ -692,4 +692,25 @@ function oenology_get_settings_page_tabs() {
);
return $tabs;
}
+
+/**
+ * Add Section Text for the Varietal Settings Section
+ */
+function oenology_get_varietal_text() {
+
+ $oenology_options = oenology_get_options();
+ $option_parameters = oenology_get_option_parameters();
+ $oenology_varietals = $option_parameters['varietal']['valid_options'];
+ foreach ( $oenology_varietals as $varietal ) {
+ if ( $varietal['name'] == $oenology_options['varietal'] ) {
+ $oenology_current_varietal = $varietal;
+ }
+ }
+ $text = '';
+ $text .= '<p>"Varietal" refers to wine made from exclusively or predominantly one variety of grape. Each varietal has unique flavor and aromatic characteristics. Refer to the contextual help screen for descriptions and help regarding each theme option.</p>';
+ $text .= '<img class="oenology-varietal-thumb" src="' . get_template_directory_uri() . '/varietals/' . $oenology_options['varietal'] . '.png' . '" width="150px" height="110px" alt="' . $oenology_options['varietal'] . '" />';
+ $text .= '<h4>Current Varietal</h4>';
+ $text .= '<dl><dt><strong>' . $oenology_current_varietal['title'] . '</strong></dt><dd>' . $oenology_current_varietal['description'] . '</dd></dl>';
+ return $text;
+}
?>

0 comments on commit 791d6a9

Please sign in to comment.
Something went wrong with that request. Please try again.