| | 589 | |
| | 590 | function 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( 'twentyeleven_color_scheme', array( |
| | 599 | 'title' => __( 'Color Scheme', 'twentyeleven' ), |
| | 600 | 'priority' => 35, |
| | 601 | ) ); |
| | 602 | |
| | 603 | $options = twentyeleven_get_theme_options(); |
| | 604 | $defaults = twentyeleven_get_default_theme_options(); |
| | 605 | |
| | 606 | $wp_customize->add_setting( 'twentyeleven_theme_options[color_scheme]', array( |
| | 607 | 'default' => $defaults['color_scheme'], |
| | 608 | 'type' => 'option', |
| | 609 | 'capability' => 'edit_theme_options', |
| | 610 | ) ); |
| | 611 | |
| | 612 | $schemes = twentyeleven_color_schemes(); |
| | 613 | $choices = array(); |
| | 614 | foreach ($schemes as $scheme) { |
| | 615 | $choices[$scheme['value']] = $scheme['label']; |
| | 616 | } |
| | 617 | |
| | 618 | $wp_customize->add_control( 'twentyeleven_color_scheme', array( |
| | 619 | 'label' => __( 'Color Scheme', 'twentyeleven' ), |
| | 620 | 'section' => 'twentyeleven_color_scheme', |
| | 621 | 'settings' => 'twentyeleven_theme_options[color_scheme]', |
| | 622 | 'type' => 'radio', |
| | 623 | 'choices' => $choices, |
| | 624 | ) ); |
| | 625 | |
| | 626 | $wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array( |
| | 627 | 'default' => twentyeleven_get_default_link_color($options['color_scheme']), |
| | 628 | 'type' => 'option', |
| | 629 | 'sanitize_callback' => 'twentyeleven_sanitize_hexcolor', |
| | 630 | 'capability' => 'edit_theme_options', |
| | 631 | ) ); |
| | 632 | |
| | 633 | $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( |
| | 634 | 'label' => __( 'Link Color', 'twentyeleven' ), |
| | 635 | 'section' => 'twentyeleven_color_scheme', |
| | 636 | 'settings' => 'twentyeleven_theme_options[link_color]', |
| | 637 | ) ) ); |
| | 638 | |
| | 639 | $wp_customize->add_section( 'twentyeleven_layout', array( |
| | 640 | 'title' => __( 'Default Layout', 'twentyeleven' ), |
| | 641 | 'priority' => 40, |
| | 642 | ) ); |
| | 643 | |
| | 644 | $wp_customize->add_setting( 'twentyeleven_theme_options[theme_layout]', array( |
| | 645 | 'type' => 'option', |
| | 646 | 'default' => $defaults['theme_layout'], |
| | 647 | 'sanitize_callback' => 'sanitize_key', |
| | 648 | ) ); |
| | 649 | |
| | 650 | $layouts = twentyeleven_layouts(); |
| | 651 | $choices = array(); |
| | 652 | foreach ($layouts as $layout) { |
| | 653 | $choices[$layout['value']] = $layout['label']; |
| | 654 | } |
| | 655 | |
| | 656 | $wp_customize->add_control( 'twentyeleven_theme_options[theme_layout]', array( |
| | 657 | 'section' => 'twentyeleven_layout', |
| | 658 | 'type' => 'radio', |
| | 659 | 'choices' => $choices, |
| | 660 | ) ); |
| | 661 | |
| | 662 | if ( $wp_customize->is_preview() && ! is_admin() ) |
| | 663 | add_action( 'wp_footer', 'twentyeleven_customize_preview', 21); |
| | 664 | } |
| | 665 | add_action( 'customize_register', 'twentyeleven_customize_register' ); |
| | 666 | |
| | 667 | |
| | 668 | function twentyeleven_sanitize_hexcolor($color) { |
| | 669 | return '#'.sanitize_hexcolor($color); |
| | 670 | } |
| | 671 | |
| | 672 | |
| | 673 | function twentyeleven_customize_preview() { |
| | 674 | ?> |
| | 675 | <script type="text/javascript"> |
| | 676 | wp.customize('blogname',function( value ) { |
| | 677 | value.bind(function(to) { |
| | 678 | jQuery('#site-title a').html(to); |
| | 679 | }); |
| | 680 | }); |
| | 681 | wp.customize('blogdescription',function( value ) { |
| | 682 | value.bind(function(to) { |
| | 683 | jQuery('#site-description').html(to); |
| | 684 | }); |
| | 685 | }); |
| | 686 | wp.customize( 'header_textcolor', function( value ) { |
| | 687 | value.bind( function( to ) { |
| | 688 | jQuery('#site-title a, #site-description').css('color', to ? '#' + to : '' ); |
| | 689 | }); |
| | 690 | }); |
| | 691 | </script> |
| | 692 | <?php |
| | 693 | } |