get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; } add_action( 'customize_register', 'thebox_customize_register' ); /** * Binds JS handlers to make Theme Customizer preview reload changes asynchronously. */ function thebox_customize_preview_js() { wp_enqueue_script( 'thebox_customizer', get_template_directory_uri() . '/js/customizer.js', array( 'customize-preview' ), '20130508', true ); } add_action( 'customize_preview_init', 'thebox_customize_preview_js' ); /** * The Box Customizer * */ function thebox_theme_customizer( $wp_customize ) { // Accent Color $wp_customize->add_setting( 'color_primary', array( 'default' => '#0fa5d9', 'type' => 'option', 'capability' => 'edit_theme_options', 'sanitize_callback' => 'sanitize_hex_color' ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'color_primary', array( 'label' => __( 'Accent Color', 'thebox' ), 'section' => 'colors', 'settings' => 'color_primary' ) ) ); } add_action('customize_register', 'thebox_theme_customizer'); /** * Convert hex to rgb * */ function hex2rgb($hex) { $hex = str_replace("#", "", $hex); if(strlen($hex) == 3) { $r = hexdec(substr($hex,0,1).substr($hex,0,1)); $g = hexdec(substr($hex,1,1).substr($hex,1,1)); $b = hexdec(substr($hex,2,1).substr($hex,2,1)); } else { $r = hexdec(substr($hex,0,2)); $g = hexdec(substr($hex,2,2)); $b = hexdec(substr($hex,4,2)); } $rgb = array($r, $g, $b); return implode(",", $rgb); // returns the rgb values separated by commas } /** * Add CSS in for styles handled by the theme customizer * */ function add_color_styles() { ?>