get_setting( 'blogname' )->transport = 'postMessage'; $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; // Add color scheme setting and control. $wp_customize->add_setting( 'color_scheme', array( 'default' => 'default', 'sanitize_callback' => 'twentyfifteen_sanitize_color_scheme', 'transport' => 'postMessage', ) ); $wp_customize->add_setting( 'color_scheme_css', array( 'default' => '', 'transport' => 'postMessage', ) ); $wp_customize->add_control( 'color_scheme', array( 'label' => esc_html__( 'Base Color Scheme', 'twentyfifteen' ), 'section' => 'colors', 'type' => 'select', 'choices' => twentyfifteen_get_color_scheme_choices(), 'priority' => 1, ) ); // Add custom header and sidebar text color setting and control. $wp_customize->add_setting( 'sidebar_textcolor', array( 'default' => $color_scheme[4], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'sidebar_textcolor', array( 'label' => esc_html__( 'Header and Sidebar Text Color', 'twentyfifteen' ), 'description' => esc_html__( 'Only applied to the sidebar on wider screens. On small screens the sidebar will become the header.', 'twentyfifteen' ), 'section' => 'colors', ) ) ); // Remove the core header textcolor control, as it shares the sidebar text color. $wp_customize->remove_control( 'header_textcolor' ); // Add custom header and sidebar background color setting and control. $wp_customize->add_setting( 'header_background_color', array( 'default' => $color_scheme[1], 'sanitize_callback' => 'sanitize_hex_color', 'transport' => 'postMessage', ) ); $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'header_background_color', array( 'label' => esc_html__( 'Header and Sidebar Background Color', 'twentyfifteen' ), 'description' => esc_html__( 'Only applied to the sidebar on wider screens. On small screens the sidebar will become the header.', 'twentyfifteen' ), 'section' => 'colors', ) ) ); // Add an additional description to the header image section. $wp_customize->get_section( 'header_image' )->description = esc_html__( 'Only applied to the sidebar on wide screens. On small screens it will be applied to the header.', 'twentyfifteen' ); } add_action( 'customize_register', 'twentyfifteen_customize_register', 11 ); /** * Register color schemes for Twenty Fifteen. * Can be filtered with twentyfifteen_color_schemes. * * The order of colors in a colors array: * 1. Main Background Color. * 2. Sidebar Background Color. * 3. Box Background Bolor. * 4. Main Text and Link Color. * 5. Sidebar Text and Link Color. * 6. Meta Box Background Color. * * @since Twenty Fifteen 1.0 * * @return array An associative array of color scheme options. */ function twentyfifteen_get_color_schemes() { return apply_filters( 'twentyfifteen_color_schemes', array( 'default' => array( 'label' => esc_html__( 'Default', 'twentyfifteen' ), 'colors' => array( '#f1f1f1', '#ffffff', '#ffffff', '#333333', '#333333', '#f7f7f7', ), ), 'dark' => array( 'label' => esc_html__( 'Dark', 'twentyfifteen' ), 'colors' => array( '#111111', '#202020', '#202020', '#bebebe', '#bebebe', '#1b1b1b', ), ), 'yellow' => array( 'label' => esc_html__( 'Yellow', 'twentyfifteen' ), 'colors' => array( '#f4ca16', '#ffdf00', '#ffffff', '#111111', '#111111', '#f1f1f1', ), ), 'pink' => array( 'label' => esc_html__( 'Pink', 'twentyfifteen' ), 'colors' => array( '#ffe5d1', '#e53b51', '#ffffff', '#352712', '#ffffff', '#f1f1f1', ), ), 'purple' => array( 'label' => esc_html__( 'Purple', 'twentyfifteen' ), 'colors' => array( '#674970', '#2e2256', '#ffffff', '#2e2256', '#ffffff', '#f1f1f1', ), ), 'blue' => array( 'label' => esc_html__( 'Blue', 'twentyfifteen' ), 'colors' => array( '#e9f2f9', '#55c3dc', '#ffffff', '#22313f', '#ffffff', '#f1f1f1', ), ), ) ); } if ( ! function_exists( 'twentyfifteen_get_color_scheme' ) ) : /** * Returns an array of either the current or default color scheme hex values. * * @since Twenty Fifteen 1.0 * * @return array */ function twentyfifteen_get_color_scheme() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); $color_schemes = twentyfifteen_get_color_schemes(); if ( array_key_exists( $color_scheme_option, $color_schemes ) ) { return $color_schemes[ $color_scheme_option ]['colors']; } return $color_schemes['default']['colors']; } endif; // twentyfifteen_get_color_scheme if ( ! function_exists( 'twentyfifteen_get_color_scheme_control_options' ) ) : /** * Returns an array of color scheme choices registered for Twenty Fifteen. * * @since Twenty Fifteen 1.0 * * @return array */ function twentyfifteen_get_color_scheme_choices() { $color_schemes = twentyfifteen_get_color_schemes(); $color_scheme_control_options = array(); foreach ( $color_schemes as $color_scheme => $value ) { $color_scheme_control_options[ $color_scheme ] = $value['label']; } return $color_scheme_control_options; } endif; // twentyfifteen_get_color_scheme_control_options if ( ! function_exists( 'twentyfifteen_sanitize_color_scheme' ) ) : /** * Sanitization callback for color schemes. * * @since Twenty Fifteen 1.0 * * @param string $value Color scheme name value. * * @return string Color scheme name. */ function twentyfifteen_sanitize_color_scheme( $value ) { $color_schemes = twentyfifteen_get_color_scheme_choices(); if ( ! array_key_exists( $value, $color_schemes ) ) { $value = 'default'; } return $value; } endif; // twentyfifteen_sanitize_color_scheme /** * Enqueues front-end CSS for color scheme. * * @since Twenty Fifteen 1.0 */ function twentyfifteen_color_scheme_css() { $color_scheme_option = get_theme_mod( 'color_scheme', 'default' ); $color_scheme_css = get_theme_mod( 'color_scheme_css', '' ); // Don't do anything if the default color scheme is selected. if ( 'default' === $color_scheme_option || empty( $color_scheme_css ) ) { return; } wp_add_inline_style( 'twentyfifteen-style', $color_scheme_css ); } add_action( 'wp_enqueue_scripts', 'twentyfifteen_color_scheme_css' ); /** * Binds JS listener to make Customizer color_scheme control. * Passes color scheme data as colorScheme global. * * @since Twenty Fifteen 1.0 */ function twentyfifteen_customize_control_js() { wp_enqueue_script( 'color-scheme-control', get_template_directory_uri() . '/js/color-scheme-control.js', array( 'customize-controls', 'iris', 'underscore', 'wp-util' ), '', true ); wp_localize_script( 'color-scheme-control', 'colorScheme', twentyfifteen_get_color_schemes() ); } add_action( 'customize_controls_enqueue_scripts', 'twentyfifteen_customize_control_js' ); /** * Binds JS handlers to make the Customizer preview reload changes asynchronously. * * @since Twenty Fifteen 1.0 */ function twentyfifteen_customize_preview_js() { wp_enqueue_script( 'twentyfifteen-customize-preview', get_template_directory_uri() . '/js/customize-preview.js', array( 'customize-preview' ), '20141029', true ); } add_action( 'customize_preview_init', 'twentyfifteen_customize_preview_js' ); /** * Output an Underscore template for generating CSS for the color scheme. * * The template generates the css dynamically for instant display in the Customizer preview, * and to be saved in a `theme_mod` for display on the front-end. * * @since Twenty Fifteen 1.0 */ function twentyfifteen_color_scheme_css_template() { ?>