Make WordPress Core

Ticket #20448: 20448.twentyeleven.2.diff

File 20448.twentyeleven.2.diff, 2.8 KB (added by Otto42, 13 years ago)

Add color scheme and partially working link-color options to customizer

  • wp-content/themes/twentyeleven/functions.php

     
    586586}
    587587add_filter( 'body_class', 'twentyeleven_body_classes' );
    588588
     589
     590function twentyeleven_customize_register($wp_customize) {
     591        if ( !isset( $wp_customize ) )
     592                return;
     593
     594        $wp_customize->get_setting('blogname')->transport='postMessage';
     595        $wp_customize->get_setting('blogdescription')->transport='postMessage';
     596        $wp_customize->get_setting('header_textcolor')->transport='postMessage';
     597               
     598        $wp_customize->add_section( 'color_scheme', array(
     599                'title'          => __( 'Color Scheme', 'twentyeleven' ),
     600                'priority'       => 40,
     601        ) );
     602       
     603        $options = twentyeleven_get_theme_options();
     604
     605        $wp_customize->add_setting( 'twentyeleven_theme_options[color_scheme]', array(
     606                'default'        => $options['color_scheme'],
     607                'type'           => 'option',
     608                'capability'     => 'edit_theme_options',
     609        ) );
     610               
     611        $schemes = twentyeleven_color_schemes();
     612       
     613        foreach ($schemes as $name=>$scheme) {
     614                $choices[$name] = $scheme['label'];
     615        }
     616       
     617        $wp_customize->add_control( 'color_scheme', array(
     618                'label'      => __( 'Color Scheme', 'twentyeleven' ),
     619                'section'    => 'color_scheme',
     620                'settings'   => 'twentyeleven_theme_options[color_scheme]',
     621                'type'       => 'radio',
     622                'choices'    => $choices,
     623        ) );
     624
     625        $wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array(
     626                'default'        => twentyeleven_get_default_link_color($options['color_scheme']),
     627                'type'           => 'option',
     628                'sanitize_callback' => 'twentyeleven_sanitize_hexcolor',
     629                'capability'     => 'edit_theme_options',
     630        ) );
     631       
     632        $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array(
     633                'label'   => __( 'Link Color', 'twentyeleven' ),
     634                'section' => 'color_scheme',
     635                'settings'   => 'twentyeleven_theme_options[link_color]',
     636        ) ) );
     637       
     638        if ( $wp_customize->is_preview() && ! is_admin() )
     639                add_action( 'wp_footer', 'twentyeleven_customize_preview', 21);
     640}
     641add_action( 'customize_register', 'twentyeleven_customize_register' );
     642
     643
     644function twentyeleven_sanitize_hexcolor($color) {
     645        return '#'.sanitize_hexcolor($color);
     646}
     647
     648
     649function twentyeleven_customize_preview() {
     650        ?>
     651        <script type="text/javascript">
     652        wp.customize('blogname',function( value ) {
     653                value.bind(function(to) {
     654                        jQuery('#site-title a').html(to);
     655                });
     656        });
     657        wp.customize('blogdescription',function( value ) {
     658                value.bind(function(to) {
     659                        jQuery('#site-description').html(to);
     660                });
     661        });
     662        wp.customize( 'header_textcolor', function( value ) {
     663                value.bind( function( to ) {
     664                        jQuery('#site-title a, #site-description').css('color', to ? '#' + to : '' );
     665                });
     666        });
     667        </script>
     668        <?php
     669}