Changeset 20295 for trunk/wp-includes/class-wp-customize.php
- Timestamp:
- 03/28/2012 04:14:09 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/class-wp-customize.php
r20290 r20295 15 15 protected $settings = array(); 16 16 protected $sections = array(); 17 protected $controls = array(); 17 18 18 19 /** … … 24 25 require( ABSPATH . WPINC . '/class-wp-customize-setting.php' ); 25 26 require( ABSPATH . WPINC . '/class-wp-customize-section.php' ); 27 require( ABSPATH . WPINC . '/class-wp-customize-control.php' ); 26 28 27 29 add_action( 'setup_theme', array( $this, 'setup_theme' ) ); … … 358 360 * @since 3.4.0 359 361 * 360 * @param string $id A nspecific ID of the setting. Can be a362 * @param string $id A specific ID of the setting. Can be a 361 363 * theme mod or option name. 362 364 * @param array $args Setting arguments. 363 365 */ 364 366 public function add_setting( $id, $args = array() ) { 365 $setting = new WP_Customize_Setting( $this, $id, $args ); 367 if ( is_a( $id, 'WP_Customize_Setting' ) ) 368 $setting = $id; 369 else 370 $setting = new WP_Customize_Setting( $this, $id, $args ); 366 371 367 372 $this->settings[ $setting->id ] = $setting; … … 373 378 * @since 3.4.0 374 379 * 375 * @param string $id A nspecific ID of the setting.380 * @param string $id A specific ID of the setting. 376 381 * @return object The settings object. 377 382 */ … … 386 391 * @since 3.4.0 387 392 * 388 * @param string $id A nspecific ID of the setting.393 * @param string $id A specific ID of the setting. 389 394 */ 390 395 public function remove_setting( $id ) { … … 397 402 * @since 3.4.0 398 403 * 399 * @param string $id A nspecific ID of the section.404 * @param string $id A specific ID of the section. 400 405 * @param array $args Section arguments. 401 406 */ 402 407 public function add_section( $id, $args = array() ) { 403 $section = new WP_Customize_Section( $this, $id, $args ); 408 if ( is_a( $id, 'WP_Customize_Section' ) ) 409 $section = $id; 410 else 411 $section = new WP_Customize_Section( $this, $id, $args ); 404 412 405 413 $this->sections[ $section->id ] = $section; … … 411 419 * @since 3.4.0 412 420 * 413 * @param string $id A nspecific ID of the section.421 * @param string $id A specific ID of the section. 414 422 * @return object The section object. 415 423 */ … … 424 432 * @since 3.4.0 425 433 * 426 * @param string $id A nspecific ID of the section.434 * @param string $id A specific ID of the section. 427 435 */ 428 436 public function remove_section( $id ) { 429 437 unset( $this->sections[ $id ] ); 438 } 439 440 /** 441 * Add a customize control. 442 * 443 * @since 3.4.0 444 * 445 * @param string $id A specific ID of the control. 446 * @param array $args Setting arguments. 447 */ 448 public function add_control( $id, $args = array() ) { 449 if ( is_a( $id, 'WP_Customize_Control' ) ) 450 $control = $id; 451 else 452 $control = new WP_Customize_Control( $this, $id, $args ); 453 454 $this->controls[ $control->id ] = $control; 455 } 456 457 /** 458 * Retrieve a customize control. 459 * 460 * @since 3.4.0 461 * 462 * @param string $id A specific ID of the control. 463 * @return object The settings object. 464 */ 465 public function get_control( $id ) { 466 if ( isset( $this->controls[ $id ] ) ) 467 return $this->controls[ $id ]; 468 } 469 470 /** 471 * Remove a customize setting. 472 * 473 * @since 3.4.0 474 * 475 * @param string $id A specific ID of the control. 476 */ 477 public function remove_control( $id ) { 478 unset( $this->controls[ $id ] ); 430 479 } 431 480 … … 453 502 */ 454 503 public function prepare_controls() { 455 // Prepare settings504 // Prepare controls 456 505 // Reversing makes uasort sort by time added when conflicts occur. 457 506 458 $this-> settings = array_reverse( $this->settings );459 $ settings = array();460 461 foreach ( $this-> settings as $id => $setting) {462 if ( ! isset( $this->sections[ $ setting->section ] ) || ! $setting->check_capabilities() )507 $this->controls = array_reverse( $this->controls ); 508 $controls = array(); 509 510 foreach ( $this->controls as $id => $control ) { 511 if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) 463 512 continue; 464 513 465 $this->sections[ $ setting->section ]->settings[] = $setting;466 $ settings[ $id ] = $setting;467 } 468 $this-> settings = $settings;514 $this->sections[ $control->section ]->controls[] = $control; 515 $controls[ $id ] = $control; 516 } 517 $this->controls = $controls; 469 518 470 519 // Prepare sections … … 474 523 475 524 foreach ( $this->sections as $section ) { 476 if ( ! $section->check_capabilities() || ! $section-> settings )525 if ( ! $section->check_capabilities() || ! $section->controls ) 477 526 continue; 478 527 479 usort( $section-> settings, array( $this, '_cmp_priority' ) );528 usort( $section->controls, array( $this, '_cmp_priority' ) ); 480 529 $sections[] = $section; 481 530 } … … 489 538 */ 490 539 public function enqueue_control_scripts() { 491 foreach ( $this-> settings as $setting) {492 $ setting->enqueue();540 foreach ( $this->controls as $control ) { 541 $control->enqueue(); 493 542 } 494 543 } … … 509 558 510 559 $this->add_setting( 'header_textcolor', array( 511 'label' => 'Text Color', 512 'section' => 'header', 513 'sanitize_callback' => 'sanitize_hexcolor', 514 'control' => 'color', 515 'theme_supports' => array( 'custom-header', 'header-text' ), 516 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 517 ) ); 518 519 /* 520 $this->add_setting( 'display_header', array( 521 'label' => 'Display Text', 560 // @todo: replace with a new accept() setting method 561 // 'sanitize_callback' => 'sanitize_hexcolor', 562 'control' => 'color', 563 'theme_supports' => array( 'custom-header', 'header-text' ), 564 'default' => get_theme_support( 'custom-header', 'default-text-color' ), 565 ) ); 566 567 $this->add_control( 'display_header_text', array( 568 'settings' => 'header_textcolor', 569 'label' => __( 'Display Header Text' ), 570 'section' => 'header', 571 'type' => 'checkbox', 572 ) ); 573 574 $this->add_control( 'header_textcolor', array( 575 'label' => __( 'Text Color' ), 522 576 'section' => 'header', 523 'type' => 'radio', 524 'choices' => array( 525 'show' => 'Yes', 526 'hide' => 'No' 527 ), 528 // Showing header text is actually done by setting header_textcolor to 'blank'. 529 // @todo: Do some JS magic to make this work (since we'll be hiding the textcolor input). 530 'theme_mod' => false, 531 ) ); 532 */ 577 'type' => 'color', 578 ) ); 533 579 534 580 // Input type: checkbox 535 581 // With custom value 536 582 $this->add_setting( 'header_image', array( 583 'default' => get_theme_support( 'custom-header', 'default-image' ), 584 'theme_supports' => 'custom-header', 585 ) ); 586 587 $this->add_control( 'header_image', array( 537 588 'label' => 'Header Image', 538 589 'section' => 'header', 539 'control' => 'image', 540 'default' => get_theme_support( 'custom-header', 'default-image' ), 590 'type' => 'image', 541 591 'control_params' => array( 542 592 'context' => 'custom-header', … … 560 610 // With sanitize_callback 561 611 $this->add_setting( 'background_color', array( 562 'label' => 'Background Color',563 'section' => 'background',564 'control' => 'color',565 612 'default' => get_theme_support( 'custom-background', 'default-color' ), 566 613 'sanitize_callback' => 'sanitize_hexcolor', 614 'theme_supports' => 'custom-background', 615 ) ); 616 617 $this->add_control( 'background_color', array( 618 'label' => __( 'Background Color' ), 619 'section' => 'background', 620 'type' => 'color', 567 621 ) ); 568 622 569 623 $this->add_setting( 'background_image', array( 570 'label' => 'Background Image', 624 'default' => get_theme_support( 'custom-background', 'default-image' ), 625 'theme_supports' => 'custom-background', 626 ) ); 627 628 $this->add_control( 'background_image', array( 629 'label' => __( 'Background Image' ), 571 630 'section' => 'background', 572 'control' => 'upload', 573 'default' => get_theme_support( 'custom-background', 'default-image' ), 631 'type' => 'upload', 574 632 'control_params' => array( 575 633 'context' => 'custom-background', … … 578 636 579 637 $this->add_setting( 'background_repeat', array( 580 'label' => 'Background Repeat', 638 'default' => 'repeat', 639 'theme_supports' => 'custom-background', 640 ) ); 641 642 $this->add_control( 'background_repeat', array( 643 'label' => __( 'Background Repeat' ), 581 644 'section' => 'background', 582 645 'visibility' => 'background_image', 583 ' control'=> 'radio',646 'type' => 'radio', 584 647 'choices' => array( 585 648 'no-repeat' => __('No Repeat'), … … 588 651 'repeat-y' => __('Tile Vertically'), 589 652 ), 590 'default' => 'repeat',591 653 ) ); 592 654 593 655 $this->add_setting( 'background_position_x', array( 594 'label' => 'Background Position', 656 'default' => 'left', 657 'theme_supports' => 'custom-background', 658 ) ); 659 660 $this->add_control( 'background_position_x', array( 661 'label' => __( 'Background Position' ), 595 662 'section' => 'background', 596 663 'visibility' => 'background_image', 597 ' control'=> 'radio',664 'type' => 'radio', 598 665 'choices' => array( 599 666 'left' => __('Left'), … … 601 668 'right' => __('Right'), 602 669 ), 603 'default' => 'left',604 670 ) ); 605 671 606 672 $this->add_setting( 'background_attachment', array( 607 'label' => 'Background Attachment', 673 'default' => 'fixed', 674 'theme_supports' => 'custom-background', 675 ) ); 676 677 $this->add_control( 'background_attachment', array( 678 'label' => __( 'Background Attachment' ), 608 679 'section' => 'background', 609 680 'visibility' => 'background_image', 610 ' control'=> 'radio',681 'type' => 'radio', 611 682 'choices' => array( 612 683 'fixed' => __('Fixed'), 613 684 'scroll' => __('Scroll'), 614 685 ), 615 'default' => 'fixed',616 686 ) ); 617 687 … … 637 707 } 638 708 639 $this->add_setting( "nav_menu_locations[{$location}]", array( 640 'label' => $description, 641 'theme_supports' => 'menus', // Todo: Needs also widgets -- array( 'menus', 'widgets' ) 642 'section' => 'nav', 643 'control' => 'select', 644 'choices' => $choices, 709 $menu_setting_id = "nav_menu_locations[{$location}]"; 710 711 $this->add_setting( $menu_setting_id, array( 645 712 'sanitize_callback' => 'absint', 713 'theme_supports' => 'menus', 714 ) ); 715 716 $this->add_control( $menu_setting_id, array( 717 'label' => $description, 718 'section' => 'nav', 719 'type' => 'select', 720 'choices' => $choices, 646 721 ) ); 647 722 } … … 661 736 662 737 $this->add_setting( 'show_on_front', array( 663 'label' => __( 'Front page displays' ), 738 'default' => get_option( 'show_on_front' ), 739 'capability' => 'manage_options', 740 'type' => 'option', 664 741 // 'theme_supports' => 'static-front-page', 665 'section' => 'static_front_page', 666 'control' => 'radio', 667 'choices' => $choices, 668 'default' => get_option( 'show_on_front' ), 742 ) ); 743 744 $this->add_control( 'show_on_front', array( 745 'label' => __( 'Front page displays' ), 746 'section' => 'static_front_page', 747 'type' => 'radio', 748 'choices' => $choices, 749 ) ); 750 751 $this->add_setting( 'page_on_front', array( 752 'type' => 'option', 753 'capability' => 'manage_options', 754 // 'theme_supports' => 'static-front-page', 755 ) ); 756 757 $this->add_control( 'page_on_front', array( 758 'label' => __( 'Front page' ), 759 'section' => 'static_front_page', 760 'type' => 'dropdown-pages', 761 'visibility' => array( 'show_on_front', 'page' ), 762 ) ); 763 764 $this->add_setting( 'page_for_posts', array( 669 765 'type' => 'option', 670 766 'capability' => 'manage_options', 671 ) );672 673 $this->add_setting( 'page_on_front', array(674 'label' => __( 'Front page' ),675 767 // 'theme_supports' => 'static-front-page', 676 'section' => 'static_front_page', 677 'control' => 'dropdown-pages', 678 'type' => 'option', 679 'capability' => 'manage_options', 680 'visibility' => array( 'show_on_front', 'page' ), 681 ) ); 682 683 $this->add_setting( 'page_for_posts', array( 684 'label' => __( 'Posts page' ), 685 // 'theme_supports' => 'static-front-page', 686 'section' => 'static_front_page', 687 'control' => 'dropdown-pages', 688 'type' => 'option', 689 'capability' => 'manage_options', 690 'visibility' => array( 'show_on_front', 'page' ), 768 ) ); 769 770 $this->add_control( 'page_for_posts', array( 771 'label' => __( 'Posts page' ), 772 'section' => 'static_front_page', 773 'type' => 'dropdown-pages', 774 'visibility' => array( 'show_on_front', 'page' ), 691 775 ) ); 692 776 … … 698 782 699 783 $this->add_setting( 'blogname', array( 700 'label' => __( 'Site Title' ), 701 'section' => 'strings', 702 'default' => get_option( 'blogname' ), 703 'type' => 'option', 704 'capability' => 'manage_options', 784 'default' => get_option( 'blogname' ), 785 'type' => 'option', 786 'capability' => 'manage_options', 787 ) ); 788 789 $this->add_control( 'blogname', array( 790 'label' => __( 'Site Title' ), 791 'section' => 'strings', 705 792 ) ); 706 793 707 794 $this->add_setting( 'blogdescription', array( 708 'label' => __( 'Tagline' ), 709 'section' => 'strings', 710 'default' => get_option( 'blogdescription' ), 711 'type' => 'option', 712 'capability' => 'manage_options', 795 'default' => get_option( 'blogdescription' ), 796 'type' => 'option', 797 'capability' => 'manage_options', 798 ) ); 799 800 $this->add_control( 'blogdescription', array( 801 'label' => __( 'Tagline' ), 802 'section' => 'strings', 713 803 ) ); 714 804 }
Note: See TracChangeset
for help on using the changeset viewer.