Make WordPress Core

Ticket #28979: 28979.2.diff

File 28979.2.diff, 12.1 KB (added by celloexpressions, 9 years ago)

Customizer Panels are not Sections; Panels and Sections are both containers for entirely different types of objects. We should be consistent with that fact internally. Not sure how to patch this exactly, but wp-includes/class-wp-customize-section.php should be renamed to class-wp-customize-container.php, with the contents as indicated in the patch (actual diff is not as big). Also merges support for mixed priorities by default. Needs thorough review (but a proper diff first would be good).

  • src/wp-admin/css/customize-controls.css

     
    105105#customize-theme-controls .control-section.open .accordion-section-title,
    106106#customize-theme-controls .control-section .accordion-section-title:focus {
    107107        color: #222;
    108         background: #f5f5f5;
     108        background: #eee;
    109109}
    110110
    111111.js .control-section:hover .accordion-section-title,
     
    112112.js .control-section .accordion-section-title:hover,
    113113.js .control-section.open .accordion-section-title,
    114114.js .control-section .accordion-section-title:focus {
    115         background: #f5f5f5;
     115        background: #eee;
    116116}
    117117
    118118#customize-theme-controls .control-section:hover > .accordion-section-title:after,
     
    132132}
    133133
    134134#customize-theme-controls .control-section:last-of-type.open,
    135 #customize-theme-controls .control-section:last-of-type .accordion-section-title {
     135#customize-theme-controls .control-section:last-of-type > .accordion-section-title {
    136136        border-bottom-color: #ddd;
    137137}
    138138
     
    151151        color: #555;
    152152        width: 38px;
    153153        height: 100%;
    154         margin: -11px -10px -11px 0; /* compensate for positioning */
     154        margin: -11px -10px -11px 0;
    155155        line-height: 45px;
    156156        padding-left: 5px;
    157157        border-left: 1px solid #eee;
     
    166166#customize-theme-controls .control-section.control-panel > h3.accordion-section-title:hover:after {
    167167        background: #ddd;
    168168        color: #000;
    169         border: 1px solid #d9d9d9;
    170         border-right: none;
     169        border-left: 1px solid #d9d9d9;
     170        border-top: 1px solid #d9d9d9;
     171        border-bottom: 1px solid #d9d9d9;
    171172        margin-top: -12px;
    172173        line-height: 44px;
    173174        z-index: 1;
  • src/wp-admin/customize.php

     
    161161
    162162                        <div id="customize-theme-controls"><ul>
    163163                                <?php
    164                                 foreach ( $wp_customize->panels() as $panel ) {
    165                                         $panel->maybe_render();
     164                                foreach ( $wp_customize->containers() as $container ) {
     165                                        $container->maybe_render();
    166166                                }
    167                                 foreach ( $wp_customize->sections() as $section ) {
    168                                         $section->maybe_render();
    169                                 }
    170167                                ?>
    171168                        </ul></div>
    172169                </div>
  • src/wp-includes/class-wp-customize-container.php

     
     1<?php
     2/**
     3 * Customize Container Class.
     4 *
     5 * A UI container for Customizer components, managed by the WP_Customize_Manager.
     6 *
     7 * @package WordPress
     8 * @subpackage Customize
     9 * @since 4.0.0
     10 */
     11abstract class WP_Customize_Container {
     12
     13        /**
     14         * WP_Customize_Manager instance.
     15         *
     16         * @since 4.0.0
     17         * @access public
     18         * @var WP_Customize_Manager
     19         */
     20        public $manager;
     21
     22        /**
     23         * Unique identifier.
     24         *
     25         * @since 4.0.0
     26         * @access public
     27         * @var string
     28         */
     29        public $id;
     30
     31        /**
     32         * Priority of the container, which determines display order.
     33         *
     34         * @since 4.0.0
     35         * @access public
     36         * @var integer
     37         */
     38        public $priority = 160;
     39
     40        /**
     41         * Capability required for the container.
     42         *
     43         * @since 4.0.0
     44         * @access public
     45         * @var string
     46         */
     47        public $capability = 'edit_theme_options';
     48
     49        /**
     50         * Theme feature support requied for the container.
     51         *
     52         * @since 4.0.0
     53         * @access public
     54         * @var string|array
     55         */
     56        public $theme_supports = '';
     57
     58        /**
     59         * Title to show in the UI.
     60         *
     61         * @since 4.0.0
     62         * @access public
     63         * @var string
     64         */
     65        public $title = '';
     66
     67        /**
     68         * Description to show in the UI.
     69         *
     70         * @since 4.0.0
     71         * @access public
     72         * @var string
     73         */
     74        public $description = '';
     75
     76        /**
     77         * Constructor.
     78         *
     79         * Any supplied $args override class property defaults.
     80         *
     81         * @since 4.0.0
     82         *
     83         * @param WP_Customize_Manager $manager Customizer bootstrap instance.
     84         * @param string               $id      An specific ID for the container.
     85         * @param array                $args    Container arguments.
     86         */
     87        public function __construct( $manager, $id, $args = array() ) {
     88                $keys = array_keys( get_object_vars( $this ) );
     89                foreach ( $keys as $key ) {
     90                        if ( isset( $args[ $key ] ) )
     91                                $this->$key = $args[ $key ];
     92                }
     93
     94                $this->manager = $manager;
     95                $this->id = $id;
     96
     97                return $this;
     98        }
     99
     100        /**
     101         * Checks required user capabilities and whether the theme has the
     102         * feature support required by the container.
     103         *
     104         * @since 4.0.0
     105         *
     106         * @return bool False if theme doesn't support the container or user doesn't have the capability.
     107         */
     108        public final function check_capabilities() {
     109                if ( $this->capability && ! call_user_func_array( 'current_user_can', (array) $this->capability ) )
     110                        return false;
     111
     112                if ( $this->theme_supports && ! call_user_func_array( 'current_theme_supports', (array) $this->theme_supports ) )
     113                        return false;
     114
     115                return true;
     116        }
     117
     118        /**
     119         * Check capabilities and render the container.
     120         *
     121         * @since 4.0.0
     122         */
     123        public final function maybe_render() {
     124                if ( ! $this->check_capabilities() )
     125                        return;
     126
     127                /**
     128                 * Fires before rendering a Customizer section (or panel).
     129                 *
     130                 * @since 3.4.0
     131                 *
     132                 * @param WP_Customize_Section $this WP_Customize_Section instance.
     133                 */
     134                do_action( 'customize_render_section', $this );
     135
     136                /**
     137                 * Fires before rendering a specific Customizer section (or panel).
     138                 *
     139                 * The dynamic portion of the hook name, $this->id, refers to the ID
     140                 * of the specific Customizer container to be rendered.
     141                 *
     142                 * @since 3.4.0
     143                 */
     144                do_action( "customize_render_section_{$this->id}" );
     145
     146                $this->render();
     147        }
     148
     149        /**
     150         * Render the container, and the objects that have been added to it.
     151         *
     152         * @since 4.0.0
     153         */
     154        abstract protected function render();
     155}
     156
     157
     158/**
     159 * Customize Panel Class.
     160 *
     161 * A UI container for sections, managed by the WP_Customize_Manager.
     162 *
     163 * @package WordPress
     164 * @subpackage Customize
     165 * @since 4.0.0
     166 */
     167class WP_Customize_Panel extends WP_Customize_Container {
     168
     169        /**
     170         * Customizer sections for this panel.
     171         *
     172         * @since 4.0.0
     173         * @access public
     174         * @var array
     175         */
     176        public $sections;
     177
     178        /**
     179         * Constructor.
     180         *
     181         * Any supplied $args override class property defaults.
     182         *
     183         * @since 4.0.0
     184         * @access public
     185         *
     186         * @param WP_Customize_Manager $manager Customizer bootstrap instance.
     187         * @param string               $id      An specific ID of the section.
     188         * @param array                $args    Optional. Section arguments. Default empty array.
     189         */
     190        public function __construct( $manager, $id, $args = array() ) {
     191                parent::__construct( $manager, $id, $args );
     192
     193                $this->sections = array(); // Users cannot customize the $sections array.
     194
     195                return $this;
     196        }
     197
     198        /**
     199         * Render the panel, and the sections that have been added to it.
     200         *
     201         * @since 4.0.0
     202         * @access protected
     203         */
     204        protected function render() {
     205                ?>
     206                <li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="control-section control-panel accordion-section">
     207                        <h3 class="accordion-section-title" tabindex="0">
     208                                <?php echo esc_html( $this->title ); ?>
     209                                <span class="screen-reader-text"><?php _e( 'Press return or enter to open panel' ); ?></span>
     210                        </h3>
     211                        <span class="control-panel-back" tabindex="-1"><span class="screen-reader-text"><?php _e( 'Back' ); ?></span></span>
     212                        <ul class="accordion-sub-container control-panel-content">
     213                                <li class="accordion-section control-section<?php if ( empty( $this->description ) ) echo ' cannot-expand'; ?>">
     214                                        <div class="accordion-section-title" tabindex="0">
     215                                                <span class="preview-notice"><?php
     216                                                        /* translators: %s is the site/panel title in the Customizer */
     217                                                        echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' );
     218                                                ?></span>
     219                                        </div>
     220                                        <?php if ( ! empty( $this->description ) ) : ?>
     221                                                <div class="accordion-section-content description">
     222                                                        <?php echo $this->description; ?>
     223                                                </div>
     224                                        <?php endif; ?>
     225                                </li>
     226                                <?php
     227                                foreach ( $this->sections as $section ) {
     228                                        $section->maybe_render();
     229                                }
     230                                ?>
     231                        </ul>
     232                </li>
     233                <?php
     234        }
     235}
     236
     237
     238/**
     239 * Customize Section Class.
     240 *
     241 * A UI container for controls, managed by the WP_Customize_Manager.
     242 *
     243 * @package WordPress
     244 * @subpackage Customize
     245 * @since 3.4.0
     246 */
     247class WP_Customize_Section extends WP_Customize_Container {
     248
     249        /**
     250         * Panel in which to show the section, making it a sub-section.
     251         *
     252         * @since 4.0.0
     253         * @access public
     254         * @var string
     255         */
     256        public $panel = '';
     257
     258        /**
     259         * Customizer controls for this section.
     260         *
     261         * @since 3.4.0
     262         * @access public
     263         * @var array
     264         */
     265        public $controls;
     266
     267        /**
     268         * Constructor.
     269         *
     270         * Any supplied $args override class property defaults.
     271         *
     272         * @since 3.4.0
     273         *
     274         * @param WP_Customize_Manager $manager Customizer bootstrap instance.
     275         * @param string               $id      An specific ID of the section.
     276         * @param array                $args    Section arguments.
     277         */
     278        public function __construct( $manager, $id, $args = array() ) {
     279                parent::__construct( $manager, $id, $args );
     280
     281                $this->controls = array(); // Users cannot customize the $controls array.
     282
     283                return $this;
     284        }
     285
     286        /**
     287         * Render the section, and the controls that have been added to it.
     288         *
     289         * @since 3.4.0
     290         */
     291        protected function render() {
     292                $classes = 'control-section accordion-section';
     293                if ( $this->panel ) {
     294                        $classes .= ' control-subsection';
     295                }
     296                ?>
     297                <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     298                        <h3 class="accordion-section-title" tabindex="0">
     299                                <?php echo esc_html( $this->title ); ?>
     300                                <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
     301                        </h3>
     302                        <ul class="accordion-section-content">
     303                                <?php if ( ! empty( $this->description ) ) : ?>
     304                                <li><p class="description customize-section-description"><?php echo $this->description; ?></p></li>
     305                                <?php endif; ?>
     306                                <?php
     307                                foreach ( $this->controls as $control )
     308                                        $control->maybe_render();
     309                                ?>
     310                        </ul>
     311                </li>
     312                <?php
     313        }
     314}
  • src/wp-includes/class-wp-customize-manager.php

     
    4343         */
    4444        public $widgets;
    4545
    46         protected $settings = array();
    47         protected $panels   = array();
    48         protected $sections = array();
    49         protected $controls = array();
     46        protected $settings   = array();
     47        protected $containers = array();
     48        protected $panels     = array();
     49        protected $sections   = array();
     50        protected $controls   = array();
    5051
    5152        protected $nonce_tick;
    5253
     
    6667         */
    6768        public function __construct() {
    6869                require( ABSPATH . WPINC . '/class-wp-customize-setting.php' );
    69                 require( ABSPATH . WPINC . '/class-wp-customize-section.php' );
     70                require( ABSPATH . WPINC . '/class-wp-customize-container.php' );
    7071                require( ABSPATH . WPINC . '/class-wp-customize-control.php' );
    7172                require( ABSPATH . WPINC . '/class-wp-customize-widgets.php' );
    7273
     
    305306        }
    306307
    307308        /**
     309         * Get the registered containers.
     310         *
     311         * @since 4.0.0
     312         *
     313         * @return array
     314         */
     315        public function containers() {
     316                return $this->containers;
     317        }
     318
     319        /**
    308320         * Get the registered sections.
    309321         *
    310322         * @since 3.4.0
     
    890902                        $panels[] = $panel;
    891903                }
    892904                $this->panels = $panels;
     905
     906                // Sort panels and top-level sections together.
     907                $this->containers = array_merge( $this->panels, $this->sections );
     908                uasort( $this->containers, array( $this, '_cmp_priority' ) );
    893909        }
    894910
    895911        /**