- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-content/themes/twentyeleven/inc/theme-options.php
r36797 r42343 60 60 ); 61 61 62 add_settings_field( 'link_color', __( 'Link Color', 63 add_settings_field( 'layout', __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout','theme_options', 'general' );62 add_settings_field( 'link_color', __( 'Link Color', 'twentyeleven' ), 'twentyeleven_settings_field_link_color', 'theme_options', 'general' ); 63 add_settings_field( 'layout', __( 'Default Layout', 'twentyeleven' ), 'twentyeleven_settings_field_layout', 'theme_options', 'general' ); 64 64 } 65 65 add_action( 'admin_init', 'twentyeleven_theme_options_init' ); … … 100 100 ); 101 101 102 if ( ! $theme_page ) 102 if ( ! $theme_page ) { 103 103 return; 104 } 104 105 105 106 add_action( "load-$theme_page", 'twentyeleven_theme_options_help' ); … … 125 126 if ( method_exists( $screen, 'add_help_tab' ) ) { 126 127 // WordPress 3.3.0 127 $screen->add_help_tab( array( 128 'title' => __( 'Overview', 'twentyeleven' ), 129 'id' => 'theme-options-help', 130 'content' => $help, 128 $screen->add_help_tab( 129 array( 130 'title' => __( 'Overview', 'twentyeleven' ), 131 'id' => 'theme-options-help', 132 'content' => $help, 131 133 ) 132 134 ); … … 147 149 $color_scheme_options = array( 148 150 'light' => array( 149 'value' => 'light',150 'label' => __( 'Light', 'twentyeleven' ),151 'thumbnail' => get_template_directory_uri() . '/inc/images/light.png',151 'value' => 'light', 152 'label' => __( 'Light', 'twentyeleven' ), 153 'thumbnail' => get_template_directory_uri() . '/inc/images/light.png', 152 154 'default_link_color' => '#1b8be0', 153 155 ), 154 'dark' => array(155 'value' => 'dark',156 'label' => __( 'Dark', 'twentyeleven' ),157 'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png',156 'dark' => array( 157 'value' => 'dark', 158 'label' => __( 'Dark', 'twentyeleven' ), 159 'thumbnail' => get_template_directory_uri() . '/inc/images/dark.png', 158 160 'default_link_color' => '#e4741f', 159 161 ), … … 178 180 $layout_options = array( 179 181 'content-sidebar' => array( 180 'value' => 'content-sidebar',181 'label' => __( 'Content on left', 'twentyeleven' ),182 'value' => 'content-sidebar', 183 'label' => __( 'Content on left', 'twentyeleven' ), 182 184 'thumbnail' => get_template_directory_uri() . '/inc/images/content-sidebar.png', 183 185 ), 184 186 'sidebar-content' => array( 185 'value' => 'sidebar-content',186 'label' => __( 'Content on right', 'twentyeleven' ),187 'value' => 'sidebar-content', 188 'label' => __( 'Content on right', 'twentyeleven' ), 187 189 'thumbnail' => get_template_directory_uri() . '/inc/images/sidebar-content.png', 188 190 ), 189 'content' => array(190 'value' => 'content',191 'label' => __( 'One-column, no sidebar', 'twentyeleven' ),191 'content' => array( 192 'value' => 'content', 193 'label' => __( 'One-column, no sidebar', 'twentyeleven' ), 192 194 'thumbnail' => get_template_directory_uri() . '/inc/images/content.png', 193 195 ), … … 218 220 ); 219 221 220 if ( is_rtl() ) 222 if ( is_rtl() ) { 221 223 $default_theme_options['theme_layout'] = 'sidebar-content'; 224 } 222 225 223 226 /** … … 239 242 * Default null (or the active color scheme). 240 243 * @return string The default link color. 241 */244 */ 242 245 function twentyeleven_get_default_link_color( $color_scheme = null ) { 243 246 if ( null === $color_scheme ) { 244 $options = twentyeleven_get_theme_options();247 $options = twentyeleven_get_theme_options(); 245 248 $color_scheme = $options['color_scheme']; 246 249 } 247 250 248 251 $color_schemes = twentyeleven_color_schemes(); 249 if ( ! isset( $color_schemes[ $color_scheme ] ) ) 252 if ( ! isset( $color_schemes[ $color_scheme ] ) ) { 250 253 return false; 254 } 251 255 252 256 return $color_schemes[ $color_scheme ]['default_link_color']; … … 365 369 366 370 // Color scheme must be in our array of color scheme options 367 if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) 371 if ( isset( $input['color_scheme'] ) && array_key_exists( $input['color_scheme'], twentyeleven_color_schemes() ) ) { 368 372 $output['color_scheme'] = $input['color_scheme']; 373 } 369 374 370 375 // Our defaults for the link color may have changed, based on the color scheme. … … 372 377 373 378 // Link color must be 3 or 6 hexadecimal characters 374 if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) 379 if ( isset( $input['link_color'] ) && preg_match( '/^#?([a-f0-9]{3}){1,2}$/i', $input['link_color'] ) ) { 375 380 $output['link_color'] = '#' . strtolower( ltrim( $input['link_color'], '#' ) ); 381 } 376 382 377 383 // Theme layout must be in our array of theme layout options 378 if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) 384 if ( isset( $input['theme_layout'] ) && array_key_exists( $input['theme_layout'], twentyeleven_layouts() ) ) { 379 385 $output['theme_layout'] = $input['theme_layout']; 386 } 380 387 381 388 /** … … 397 404 */ 398 405 function twentyeleven_enqueue_color_scheme() { 399 $options = twentyeleven_get_theme_options();406 $options = twentyeleven_get_theme_options(); 400 407 $color_scheme = $options['color_scheme']; 401 408 402 if ( 'dark' == $color_scheme ) 409 if ( 'dark' == $color_scheme ) { 403 410 wp_enqueue_style( 'dark', get_template_directory_uri() . '/colors/dark.css', array(), null ); 411 } 404 412 405 413 /** … … 422 430 */ 423 431 function twentyeleven_print_link_color_style() { 424 $options = twentyeleven_get_theme_options();432 $options = twentyeleven_get_theme_options(); 425 433 $link_color = $options['link_color']; 426 434 … … 428 436 429 437 // Don't do anything if the current link color is the default. 430 if ( $default_options['link_color'] == $link_color ) 438 if ( $default_options['link_color'] == $link_color ) { 431 439 return; 440 } 432 441 ?> 433 442 <style> … … 470 479 */ 471 480 function twentyeleven_layout_classes( $existing_classes ) { 472 $options = twentyeleven_get_theme_options();481 $options = twentyeleven_get_theme_options(); 473 482 $current_layout = $options['theme_layout']; 474 483 475 if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ) ) ) 484 if ( in_array( $current_layout, array( 'content-sidebar', 'sidebar-content' ) ) ) { 476 485 $classes = array( 'two-column' ); 477 else486 } else { 478 487 $classes = array( 'one-column' ); 479 480 if ( 'content-sidebar' == $current_layout ) 488 } 489 490 if ( 'content-sidebar' == $current_layout ) { 481 491 $classes[] = 'right-sidebar'; 482 elseif ( 'sidebar-content' == $current_layout )492 } elseif ( 'sidebar-content' == $current_layout ) { 483 493 $classes[] = 'left-sidebar'; 484 else494 } else { 485 495 $classes[] = $current_layout; 496 } 486 497 487 498 /** … … 507 518 */ 508 519 function twentyeleven_customize_register( $wp_customize ) { 509 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';510 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';520 $wp_customize->get_setting( 'blogname' )->transport = 'postMessage'; 521 $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage'; 511 522 $wp_customize->get_setting( 'header_textcolor' )->transport = 'postMessage'; 512 523 513 524 if ( isset( $wp_customize->selective_refresh ) ) { 514 $wp_customize->selective_refresh->add_partial( 'blogname', array( 515 'selector' => '#site-title a', 516 'container_inclusive' => false, 517 'render_callback' => 'twentyeleven_customize_partial_blogname', 518 ) ); 519 $wp_customize->selective_refresh->add_partial( 'blogdescription', array( 520 'selector' => '#site-description', 521 'container_inclusive' => false, 522 'render_callback' => 'twentyeleven_customize_partial_blogdescription', 523 ) ); 525 $wp_customize->selective_refresh->add_partial( 526 'blogname', array( 527 'selector' => '#site-title a', 528 'container_inclusive' => false, 529 'render_callback' => 'twentyeleven_customize_partial_blogname', 530 ) 531 ); 532 $wp_customize->selective_refresh->add_partial( 533 'blogdescription', array( 534 'selector' => '#site-description', 535 'container_inclusive' => false, 536 'render_callback' => 'twentyeleven_customize_partial_blogdescription', 537 ) 538 ); 524 539 } 525 540 … … 527 542 $defaults = twentyeleven_get_default_theme_options(); 528 543 529 $wp_customize->add_setting( 'twentyeleven_theme_options[color_scheme]', array( 530 'default' => $defaults['color_scheme'], 531 'type' => 'option', 532 'capability' => 'edit_theme_options', 533 ) ); 544 $wp_customize->add_setting( 545 'twentyeleven_theme_options[color_scheme]', array( 546 'default' => $defaults['color_scheme'], 547 'type' => 'option', 548 'capability' => 'edit_theme_options', 549 ) 550 ); 534 551 535 552 $schemes = twentyeleven_color_schemes(); … … 539 556 } 540 557 541 $wp_customize->add_control( 'twentyeleven_color_scheme', array( 542 'label' => __( 'Color Scheme', 'twentyeleven' ), 543 'section' => 'colors', 544 'settings' => 'twentyeleven_theme_options[color_scheme]', 545 'type' => 'radio', 546 'choices' => $choices, 547 'priority' => 5, 548 ) ); 558 $wp_customize->add_control( 559 'twentyeleven_color_scheme', array( 560 'label' => __( 'Color Scheme', 'twentyeleven' ), 561 'section' => 'colors', 562 'settings' => 'twentyeleven_theme_options[color_scheme]', 563 'type' => 'radio', 564 'choices' => $choices, 565 'priority' => 5, 566 ) 567 ); 549 568 550 569 // Link Color (added to Color Scheme section in Customizer) 551 $wp_customize->add_setting( 'twentyeleven_theme_options[link_color]', array( 552 'default' => twentyeleven_get_default_link_color( $options['color_scheme'] ), 553 'type' => 'option', 554 'sanitize_callback' => 'sanitize_hex_color', 555 'capability' => 'edit_theme_options', 556 ) ); 557 558 $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'link_color', array( 559 'label' => __( 'Link Color', 'twentyeleven' ), 560 'section' => 'colors', 561 'settings' => 'twentyeleven_theme_options[link_color]', 562 ) ) ); 570 $wp_customize->add_setting( 571 'twentyeleven_theme_options[link_color]', array( 572 'default' => twentyeleven_get_default_link_color( $options['color_scheme'] ), 573 'type' => 'option', 574 'sanitize_callback' => 'sanitize_hex_color', 575 'capability' => 'edit_theme_options', 576 ) 577 ); 578 579 $wp_customize->add_control( 580 new WP_Customize_Color_Control( 581 $wp_customize, 'link_color', array( 582 'label' => __( 'Link Color', 'twentyeleven' ), 583 'section' => 'colors', 584 'settings' => 'twentyeleven_theme_options[link_color]', 585 ) 586 ) 587 ); 563 588 564 589 // Default Layout 565 $wp_customize->add_section( 'twentyeleven_layout', array( 566 'title' => __( 'Layout', 'twentyeleven' ), 567 'priority' => 50, 568 ) ); 569 570 $wp_customize->add_setting( 'twentyeleven_theme_options[theme_layout]', array( 571 'type' => 'option', 572 'default' => $defaults['theme_layout'], 573 'sanitize_callback' => 'sanitize_key', 574 ) ); 590 $wp_customize->add_section( 591 'twentyeleven_layout', array( 592 'title' => __( 'Layout', 'twentyeleven' ), 593 'priority' => 50, 594 ) 595 ); 596 597 $wp_customize->add_setting( 598 'twentyeleven_theme_options[theme_layout]', array( 599 'type' => 'option', 600 'default' => $defaults['theme_layout'], 601 'sanitize_callback' => 'sanitize_key', 602 ) 603 ); 575 604 576 605 $layouts = twentyeleven_layouts(); … … 580 609 } 581 610 582 $wp_customize->add_control( 'twentyeleven_theme_options[theme_layout]', array( 583 'section' => 'twentyeleven_layout', 584 'type' => 'radio', 585 'choices' => $choices, 586 ) ); 611 $wp_customize->add_control( 612 'twentyeleven_theme_options[theme_layout]', array( 613 'section' => 'twentyeleven_layout', 614 'type' => 'radio', 615 'choices' => $choices, 616 ) 617 ); 587 618 } 588 619 add_action( 'customize_register', 'twentyeleven_customize_register' );
Note: See TracChangeset
for help on using the changeset viewer.