| 450 | | add_filter( 'body_class', 'twentyeleven_layout_classes' ); |
| 451 | | No newline at end of file |
| | 450 | add_filter( 'body_class', 'twentyeleven_layout_classes' ); |
| | 451 | |
| | 452 | /** |
| | 453 | * Implements Twenty Eleven theme options into Theme Customizer |
| | 454 | * |
| | 455 | * @param $wp_customize Theme Customizer object |
| | 456 | * @return void |
| | 457 | * |
| | 458 | * @since Twenty Eleven 1.3 |
| | 459 | */ |
| | 460 | function twentyeleven_customize_register( $wp_customize ) { |
| | 461 | if ( ! isset( $wp_customize ) ) |
| | 462 | return; |
| | 463 | |
| | 464 | $wp_customize->get_setting( 'blogname' )->transport='postMessage'; |
| | 465 | $wp_customize->get_setting( 'blogdescription' )->transport='postMessage'; |
| | 466 | $wp_customize->get_setting( 'header_textcolor' )->transport='postMessage'; |
| | 467 | |
| | 468 | // Color Scheme |
| | 469 | $wp_customize->add_section( 'twentyeleven_color_scheme', array( |
| | 470 | 'title' => __( 'Color Scheme', 'twentyeleven' ), |
| | 471 | 'priority' => 35, |
| | 472 | ) ); |
| | 473 | |
| | 474 | $options = twentyeleven_get_theme_options(); |
| | 475 | $defaults = twentyeleven_get_default_theme_options(); |
| | 476 | |
| | 477 | $wp_customize->add_setting( 'twentyeleven_theme_options[color_scheme]', array( |
| | 478 | 'default' => $defaults['color_scheme'], |
| | 479 | 'type' => 'option', |
| | 480 | 'capability' => 'edit_theme_options', |
| | 481 | ) ); |
| | 482 | |
| | 483 | $schemes = twentyeleven_color_schemes(); |
| | 484 | $choices = array(); |
| | 485 | foreach ( $schemes as $scheme ) { |
| | 486 | $choices[$scheme['value']] = $scheme['label']; |
| | 487 | } |
| | 488 | |
| | 489 | $wp_customize->add_control( 'twentyeleven_color_scheme', array( |
| | 490 | 'label' => __( 'Color Scheme', 'twentyeleven' ), |
| | 491 | 'section' => 'twentyeleven_color_scheme', |
| | 492 | 'settings' => 'twentyeleven_theme_options[color_scheme]', |
| | 493 | 'type' => 'radio', |
| | 494 | 'choices' => $choices, |
| | 495 | ) ); |
| | 496 | |
| | 497 | // Link Color (added to Color Scheme section in Theme Customizer) |
| | 498 | $wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array( |
| | 499 | 'default' => twentyeleven_get_default_link_color( $options['color_scheme'] ), |
| | 500 | 'type' => 'option', |
| | 501 | 'sanitize_callback' => 'twentyeleven_sanitize_hexcolor', |
| | 502 | 'capability' => 'edit_theme_options', |
| | 503 | ) ); |
| | 504 | |
| | 505 | $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( |
| | 506 | 'label' => __( 'Link Color', 'twentyeleven' ), |
| | 507 | 'section' => 'twentyeleven_color_scheme', |
| | 508 | 'settings' => 'twentyeleven_theme_options[link_color]', |
| | 509 | ) ) ); |
| | 510 | |
| | 511 | // Default Layout |
| | 512 | $wp_customize->add_section( 'twentyeleven_layout', array( |
| | 513 | 'title' => __( 'Default Layout', 'twentyeleven' ), |
| | 514 | 'priority' => 40, |
| | 515 | ) ); |
| | 516 | |
| | 517 | $wp_customize->add_setting( 'twentyeleven_theme_options[theme_layout]', array( |
| | 518 | 'type' => 'option', |
| | 519 | 'default' => $defaults['theme_layout'], |
| | 520 | 'sanitize_callback' => 'sanitize_key', |
| | 521 | ) ); |
| | 522 | |
| | 523 | $layouts = twentyeleven_layouts(); |
| | 524 | $choices = array(); |
| | 525 | foreach ( $layouts as $layout ) { |
| | 526 | $choices[$layout['value']] = $layout['label']; |
| | 527 | } |
| | 528 | |
| | 529 | $wp_customize->add_control( 'twentyeleven_theme_options[theme_layout]', array( |
| | 530 | 'section' => 'twentyeleven_layout', |
| | 531 | 'type' => 'radio', |
| | 532 | 'choices' => $choices, |
| | 533 | ) ); |
| | 534 | |
| | 535 | if ( $wp_customize->is_preview() ) |
| | 536 | add_action( 'wp_enqueue_scripts', 'twentyeleven_customize_preview_js' ); |
| | 537 | } |
| | 538 | add_action( 'customize_register', 'twentyeleven_customize_register' ); |
| | 539 | |
| | 540 | /** |
| | 541 | * Sanitize user input hex color value |
| | 542 | * |
| | 543 | * @uses sanitize_hexcolor() |
| | 544 | * @param $color string |
| | 545 | * @return string sanitized with prefixed # character |
| | 546 | */ |
| | 547 | function twentyeleven_sanitize_hexcolor( $color ) { |
| | 548 | return '#' . sanitize_hexcolor( $color ); |
| | 549 | } |
| | 550 | |
| | 551 | /** |
| | 552 | * Bind JS handlers to make Theme Customizer preview reload changes asynchronously. |
| | 553 | * Used with blogname, blogdescription, and header_textcolor -- see twentyeleven_customize_register(). |
| | 554 | * |
| | 555 | * @since Twenty Eleven 1.3 |
| | 556 | */ |
| | 557 | function twentyeleven_customize_preview_js() { |
| | 558 | wp_enqueue_script( 'twentyeleven-customizer', get_template_directory_uri() . '/inc/theme-customizer.js', array( 'jquery' ), '20120523', true ); |
| | 559 | } |
| | 560 | No newline at end of file |