Make WordPress Core


Ignore:
Timestamp:
06/26/2014 08:16:21 PM (11 years ago)
Author:
ocean90
Message:

Customizer: Introduce a "panel" API to organize multiple sections into a one section.

Create a panel via $GLOBALS['wp_customize']->add_panel( $panel_id, $args ) and use $panel_id for the panel argument in $GLOBALS['wp_customize']->add_section( $section_id, $args ). That's it.
As an example all widget area sections are now summarized into one panel. Feedback appreciated.

props celloexpressions.
see #27406.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src

    • Property svn:ignore
      •  

        old new  
        11.wp-tests-version
        22.htaccess
         3web-store-experiences
  • trunk/src/wp-includes/class-wp-customize-section.php

    r28827 r28861  
    3737     */
    3838    public $priority = 10;
     39
     40    /**
     41     * Panel in which to show the section, making it a sub-section.
     42     *
     43     * @since 4.0.0
     44     * @access public
     45     * @var string
     46     */
     47    public $panel = '';
    3948
    4049    /**
     
    163172     */
    164173    protected function render() {
     174        $classes = 'control-section accordion-section';
     175        if ( $this->panel ) {
     176            $classes .= ' control-subsection';
     177        }
    165178        ?>
    166         <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="control-section accordion-section">
     179        <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
    167180            <h3 class="accordion-section-title" tabindex="0"><?php echo esc_html( $this->title ); ?></h3>
    168181            <ul class="accordion-section-content">
     
    179192    }
    180193}
     194
     195/**
     196 * Customize Panel Class.
     197 *
     198 * A UI container for sections, managed by the WP_Customize_Manager.
     199 *
     200 * @package WordPress
     201 * @subpackage Customize
     202 * @since 4.0.0
     203 */
     204class WP_Customize_Panel extends WP_Customize_Section {
     205
     206    /**
     207     * Customizer sections for this panel.
     208     *
     209     * @since 4.0.0
     210     * @access public
     211     * @var array
     212     */
     213    public $sections;
     214
     215    /**
     216     * Constructor.
     217     *
     218     * Any supplied $args override class property defaults.
     219     *
     220     * @since 4.0.0
     221     *
     222     * @param WP_Customize_Manager $manager Customizer bootstrap instance.
     223     * @param string               $id      An specific ID of the section.
     224     * @param array                $args    Section arguments.
     225     */
     226    public function __construct( $manager, $id, $args = array() ) {
     227        parent::__construct( $manager, $id, $args );
     228
     229        $this->sections = array(); // Users cannot customize the $sections array.
     230
     231        return $this;
     232    }
     233
     234    /**
     235     * Render the panel, and the sections that have been added to it.
     236     *
     237     * @since 4.0.0
     238     */
     239    protected function render() {
     240        ?>
     241        <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="control-section control-panel accordion-section">
     242            <h3 class="accordion-section-title" tabindex="0"><?php echo esc_html( $this->title ); ?></h3>
     243            <span class="control-panel-back" tabindex="0"><span class="screen-reader-text">Back to Customize</span></span>
     244            <ul class="accordion-sub-container control-panel-content">
     245                <li class="accordion-section control-section<?php if ( empty( $this->description ) ) echo ' cannot-expand'; ?>">
     246                    <div class="accordion-section-title" tabindex="0">
     247                        <span class="preview-notice"><?php
     248                            /* translators: %s is the panel title in the Customize/Live Preview pane */
     249                            echo sprintf( 'You are customizing %s', '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' );
     250                        ?></span>
     251                    </div>
     252                    <?php if ( ! empty( $this->description ) ) : ?>
     253                        <div class="accordion-section-content description">
     254                            <?php echo $this->description; ?>
     255                        </div>
     256                    <?php endif; ?>
     257                </li>
     258                <?php
     259                foreach ( $this->sections as $section ) {
     260                    $section->maybe_render();
     261                }
     262                ?>
     263            </ul>
     264        </li>
     265        <?php
     266    }
     267}
Note: See TracChangeset for help on using the changeset viewer.