Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

First round for the new theme customize controls.

  • Loading branch information...
commit 683b77cc3db9287cee168b8a374a049947e323e9 1 parent e50ae6d
Justin Tadlock authored
38 classes/customize-control-textarea.php
View
@@ -0,0 +1,38 @@
+<?php
+/**
+ * The textarea customize control extends the WP_Customize_Control class. This class allows
+ * developers to create textarea settings within the WordPress theme customizer.
+ *
+ * @package Hybrid
+ * @subpackage Classes
+ * @author Justin Tadlock <justin@justintadlock.com>
+ * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
+ * @link http://themehybrid.com/hybrid-core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+/**
+ * Textarea customize control class.
+ *
+ * @since 1.4.0
+ */
+class Hybrid_Customize_Control_Textarea extends WP_Customize_Control {
+
+ public $type = 'textarea';
+
+ public function __construct( $manager, $id, $args = array() ) {
+
+ parent::__construct( $manager, $id, $args );
+ }
+
+ public function render_content() { ?>
+ <label>
+ <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
+ <div class="customize-control-content">
+ <textarea cols="45" rows="5" <?php $this->link(); ?>><?php echo esc_textarea( $this->value() ); ?></textarea>
+ </div>
+ </label>
+ <?php }
+}
+
+?>
112 functions/customize.php
View
@@ -0,0 +1,112 @@
+<?php
+/**
+ * Functions for registering and setting theme settings that tie into the WordPress theme customizer.
+ * This file loads additional classes and adds settings to the customizer for the built-in Hybrid Core
+ * settings.
+ *
+ * @package HybridCore
+ * @subpackage Functions
+ * @author Justin Tadlock <justin@justintadlock.com>
+ * @copyright Copyright (c) 2008 - 2012, Justin Tadlock
+ * @link http://themehybrid.com/hybrid-core
+ * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
+ */
+
+/* Load custom control classes. */
+add_action( 'customize_register', 'hybrid_load_customize_controls', 1 );
+
+/* Register custom sections, settings, and controls. */
+add_action( 'customize_register', 'hybrid_customize_register' );
+
+/**
+ * Loads framework-specific customize control classes. Customize control classes extend the WordPress
+ * WP_Customize_Control class to create unique classes that can be used within the framework.
+ *
+ * @since 1.4.0
+ * @access private
+ */
+function hybrid_load_customize_controls() {
+
+ /* Loads the textarea customize control class. */
+ require_once( trailingslashit( HYBRID_CLASSES ) . 'customize-control-textarea.php' );
+}
+
+/**
+ * Registers custom sections, settings, and controls for the $wp_customize instance.
+ *
+ * @since 1.4.0
+ * @access private
+ * @param object $wp_customize
+ */
+function hybrid_customize_register( $wp_customize ) {
+
+ /* Get supported theme settings. */
+ $supports = get_theme_support( 'hybrid-core-theme-settings' );
+
+ /* Add the footer section, setting, and control if theme supports the 'footer' setting. */
+ if ( is_array( $supports[0] ) && in_array( 'footer', $supports[0] ) ) {
+
+ $wp_customize->add_section(
+ 'hybrid-core-footer',
+ array(
+ 'title' => __( 'Footer', 'hybrid-core' ),
+ 'priority' => 200,
+ 'capability' => 'edit_theme_options',
+ // 'theme_supports' => 'hybrid-core-theme-settings'
+ )
+ );
+
+ $default_settings = hybrid_get_default_theme_settings();
+
+ $wp_customize->add_setting(
+ hybrid_get_prefix() . '_theme_settings[footer_insert]',
+ array(
+ 'default' => $default_settings['footer_insert'],
+ 'type' => 'option',
+ 'capability' => 'edit_theme_options',
+ //'sanitize_js_callback' => 'do_shortcode',
+ 'transport' => 'postMessage',
+ )
+ );
+
+ $wp_customize->add_control(
+ new Hybrid_Customize_Control_Textarea(
+ $wp_customize,
+ 'hybrid-core-footer',
+ array(
+ 'label' => __( 'Footer', 'hybrid-core' ),
+ 'section' => 'hybrid-core-footer',
+ 'settings' => hybrid_get_prefix() . '_theme_settings[footer_insert]',
+ )
+ )
+ );
+
+ if ( $wp_customize->is_preview() && !is_admin() )
+ add_action( 'wp_footer', 'hybrid_customize_preview', 21 );
+ }
+}
+
+/**
+ * Handles changing settings for the live preview of the theme.
+ *
+ * @since 1.4.0
+ * @access private
+ */
+function hybrid_customize_preview() {
+ ?>
+ <script type="text/javascript">
+ wp.customize(
+ '<?php echo hybrid_get_prefix(); ?>_theme_settings[footer_insert]',
+ function( value ) {
+ value.bind(
+ function( to ) {
+ jQuery( '#footer .wrap' ).html( to );
+ }
+ );
+ }
+ );
+ </script>
+ <?php
+}
+
+?>
3  hybrid.php
View
@@ -236,6 +236,9 @@ function functions() {
/* Load the theme settings functions if supported. */
require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'settings.php' );
+ /* Load the customizer functions if theme settings are supported. */
+ require_if_theme_supports( 'hybrid-core-theme-settings', trailingslashit( HYBRID_FUNCTIONS ) . 'customize.php' );
+
/* Load the menus functions if supported. */
require_if_theme_supports( 'hybrid-core-menus', trailingslashit( HYBRID_FUNCTIONS ) . 'menus.php' );
Please sign in to comment.
Something went wrong with that request. Please try again.