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-manager.php

    r28546 r28861  
    4646
    4747    protected $settings = array();
     48    protected $panels   = array();
    4849    protected $sections = array();
    4950    protected $controls = array();
     
    313314    public function sections() {
    314315        return $this->sections;
     316    }
     317
     318    /**
     319     * Get the registered panels.
     320     *
     321     * @since 4.0.0
     322     *
     323     * @return array
     324     */
     325    public function panels() {
     326        return $this->panels;
    315327    }
    316328
     
    649661
    650662    /**
     663     * Add a customize panel.
     664     *
     665     * @since 4.0.0
     666     *
     667     * @param WP_Customize_Panel|string $id   Customize Panel object, or Panel ID.
     668     * @param array                     $args Panel arguments.
     669     */
     670    public function add_panel( $id, $args = array() ) {
     671        if ( is_a( $id, 'WP_Customize_Panel' ) ) {
     672            $panel = $id;
     673        }
     674        else {
     675            $panel = new WP_Customize_Panel( $this, $id, $args );
     676        }
     677
     678        $this->panels[ $panel->id ] = $panel;
     679    }
     680
     681    /**
     682     * Retrieve a customize panel.
     683     *
     684     * @since 4.0.0
     685     *
     686     * @param string $id Panel ID.
     687     * @return WP_Customize_Panel
     688     */
     689    public function get_panel( $id ) {
     690        if ( isset( $this->panels[ $id ] ) ) {
     691            return $this->panels[ $id ];
     692        }
     693    }
     694
     695    /**
     696     * Remove a customize panel.
     697     *
     698     * @since 4.0.0
     699     *
     700     * @param string $id Panel ID.
     701     */
     702    public function remove_panel( $id ) {
     703        unset( $this->panels[ $id ] );
     704    }
     705
     706    /**
    651707     * Add a customize section.
    652708     *
     
    750806
    751807    /**
    752      * Prepare settings and sections.
     808     * Prepare panels, sections, and controls.
    753809     *
    754810     * For each, check if required related components exist,
     
    764820
    765821        foreach ( $this->controls as $id => $control ) {
    766             if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() )
     822            if ( ! isset( $this->sections[ $control->section ] ) || ! $control->check_capabilities() ) {
    767823                continue;
     824            }
    768825
    769826            $this->sections[ $control->section ]->controls[] = $control;
     
    779836
    780837        foreach ( $this->sections as $section ) {
    781             if ( ! $section->check_capabilities() || ! $section->controls )
     838            if ( ! $section->check_capabilities() || ! $section->controls ) {
    782839                continue;
     840            }
    783841
    784842            usort( $section->controls, array( $this, '_cmp_priority' ) );
    785             $sections[] = $section;
     843
     844            if ( ! $section->panel ) {
     845                // Top-level section.
     846                $sections[] = $section;
     847            } else {
     848                // This section belongs to a panel.
     849                if ( isset( $this->panels [ $section->panel ] ) ) {
     850                    $this->panels[ $section->panel ]->sections[] = $section;
     851                }
     852            }
    786853        }
    787854        $this->sections = $sections;
     855
     856        // Prepare panels.
     857        // Reversing makes uasort sort by time added when conflicts occur.
     858        $this->panels = array_reverse( $this->panels );
     859        uasort( $this->panels, array( $this, '_cmp_priority' ) );
     860        $panels = array();
     861
     862        foreach ( $this->panels as $panel ) {
     863            if ( ! $panel->check_capabilities() || ! $panel->sections ) {
     864                continue;
     865            }
     866
     867            usort( $panel->sections, array( $this, '_cmp_priority' ) );
     868            $panels[] = $panel;
     869        }
     870        $this->panels = $panels;
    788871    }
    789872
Note: See TracChangeset for help on using the changeset viewer.