Make WordPress Core

Ticket #30737: 30737.4.diff

File 30737.4.diff, 18.1 KB (added by westonruter, 10 years ago)

Additional changes: https://github.com/xwp/wordpress-develop/compare/e07a0f0...3758798

  • src/wp-admin/customize.php

    diff --git src/wp-admin/customize.php src/wp-admin/customize.php
    index 178db28..4195a29 100644
    do_action( 'customize_controls_print_scripts' ); 
    184184        <div id="customize-preview" class="wp-full-overlay-main"></div>
    185185        <?php
    186186
    187         // Render control templates.
     187        // Render Panel, Section, and Control templates.
     188        $wp_customize->render_panel_templates();
     189        $wp_customize->render_section_templates();
    188190        $wp_customize->render_control_templates();
    189191
    190192        /**
    do_action( 'customize_controls_print_scripts' ); 
    268270
    269271        // Prepare Customize Setting objects to pass to JavaScript.
    270272        foreach ( $wp_customize->settings() as $id => $setting ) {
    271                 $settings['settings'][ $id ] = array(
    272                         'value'     => $setting->js_value(),
    273                         'transport' => $setting->transport,
    274                 );
     273                if ( $setting->check_capabilities() ) {
     274                        $settings['settings'][ $id ] = array(
     275                                'value'     => $setting->js_value(),
     276                                'transport' => $setting->transport,
     277                        );
     278                }
    275279        }
    276280
    277281        // Prepare Customize Control objects to pass to JavaScript.
    278282        foreach ( $wp_customize->controls() as $id => $control ) {
    279                 $settings['controls'][ $id ] = $control->json();
     283                if ( $control->check_capabilities() ) {
     284                        $settings['controls'][ $id ] = $control->json();
     285                }
    280286        }
    281287
    282288        // Prepare Customize Section objects to pass to JavaScript.
    283289        foreach ( $wp_customize->sections() as $id => $section ) {
    284                 $settings['sections'][ $id ] = $section->json();
     290                if ( $section->check_capabilities() ) {
     291                        $settings['sections'][ $id ] = $section->json();
     292                }
    285293        }
    286294
    287295        // Prepare Customize Panel objects to pass to JavaScript.
    288         foreach ( $wp_customize->panels() as $id => $panel ) {
    289                 $settings['panels'][ $id ] = $panel->json();
    290                 foreach ( $panel->sections as $section_id => $section ) {
    291                         $settings['sections'][ $section_id ] = $section->json();
     296        foreach ( $wp_customize->panels() as $panel_id => $panel ) {
     297                if ( $panel->check_capabilities() ) {
     298                        $settings['panels'][ $panel_id ] = $panel->json();
     299                        foreach ( $panel->sections as $section_id => $section ) {
     300                                if ( $section->check_capabilities() ) {
     301                                        $settings['sections'][ $section_id ] = $section->json();
     302                                }
     303                        }
    292304                }
    293305        }
    294306
  • src/wp-admin/js/customize-controls.js

    diff --git src/wp-admin/js/customize-controls.js src/wp-admin/js/customize-controls.js
    index 7c4a631..a52a164 100644
     
    149149        Container = api.Class.extend({
    150150                defaultActiveArguments: { duration: 'fast', completeCallback: $.noop },
    151151                defaultExpandedArguments: { duration: 'fast', completeCallback: $.noop },
     152                containerType: 'container',
    152153
    153154                /**
    154155                 * @since 4.1.0
     
    161162                        container.id = id;
    162163                        container.params = {};
    163164                        $.extend( container, options || {} );
     165                        container.templateSelector = 'customize-' + container.containerType + '-' + container.params.type;
    164166                        container.container = $( container.params.content );
     167                        if ( 0 === container.container.length ) {
     168                                container.container = $( container.getContainer() );
     169                        }
    165170
    166171                        container.deferred = {
    167172                                embedded: new $.Deferred()
     
    348353                 * Bring the container into view and then expand this and bring it into view
    349354                 * @param {Object} [params]
    350355                 */
    351                 focus: focus
     356                focus: focus,
     357
     358                /**
     359                 * Return the container html, generated from its JS template, if it exists.
     360                 *
     361                 * @since 4.2.0
     362                 */
     363                getContainer: function () {
     364                        var template,
     365                                container = this;
     366
     367                        if ( 0 !== $( '#tmpl-' + container.templateSelector ).length ) {
     368                                template = wp.template( container.templateSelector );
     369                                if ( template && container.container ) {
     370                                        return template( container.params );
     371                                }
     372                        }
     373
     374                        return '<li></li>';
     375                }
    352376        });
    353377
    354378        /**
     
    358382         * @augments wp.customize.Class
    359383         */
    360384        api.Section = Container.extend({
     385                containerType: 'section',
    361386
    362387                /**
    363388                 * @since 4.1.0
     
    527552         * @augments wp.customize.Class
    528553         */
    529554        api.Panel = Container.extend({
     555                containerType: 'panel',
     556
    530557                /**
    531558                 * @since 4.1.0
    532559                 *
     
    553580
    554581                        if ( ! panel.container.parent().is( parentContainer ) ) {
    555582                                parentContainer.append( panel.container );
     583                                panel.renderContent();
    556584                        }
    557585                        panel.deferred.embedded.resolve();
    558586                },
     
    575603                                }
    576604                        });
    577605
    578                         meta = panel.container.find( '.panel-meta:first' );
    579 
    580                         meta.find( '> .accordion-section-title' ).on( 'click keydown', function( event ) {
     606                        panel.container.on( 'click keydown', '.panel-meta > .accordion-section-title', function( event ) {
    581607                                if ( api.utils.isKeydownButNotEnterEvent( event ) ) {
    582608                                        return;
    583609                                }
    584610                                event.preventDefault(); // Keep this AFTER the key filter above
    585611
     612                                meta = panel.container.find( '.panel-meta' );
    586613                                if ( meta.hasClass( 'cannot-expand' ) ) {
    587614                                        return;
    588615                                }
     
    704731                                panelTitle.focus();
    705732                                container.scrollTop( 0 );
    706733                        }
     734                },
     735
     736                /**
     737                 * Render the panel from its JS template, if it exists.
     738                 *
     739                 * The panel's container must already exist in the DOM.
     740                 *
     741                 * @since 4.2.0
     742                 */
     743                renderContent: function () {
     744                        var template,
     745                                panel = this;
     746
     747                        // Add the content to the container.
     748                        if ( 0 !== $( '#tmpl-' + panel.templateSelector + '-content' ).length ) {
     749                                template = wp.template( panel.templateSelector + '-content' );
     750                                if ( template && panel.container ) {
     751                                        panel.container.find( '.accordion-sub-container' ).html( template( panel.params ) );
     752                                }
     753                        }
    707754                }
    708755        });
    709756
  • src/wp-includes/class-wp-customize-control.php

    diff --git src/wp-includes/class-wp-customize-control.php src/wp-includes/class-wp-customize-control.php
    index 8e7a3c5..81cc274 100644
    class WP_Customize_Control { 
    515515         * @since 4.1.0
    516516         */
    517517        final public function print_template() {
    518                 ?>
    519                 <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
    520                         <?php $this->content_template(); ?>
    521                 </script>
    522                 <?php
     518                ?>
     519                <script type="text/html" id="tmpl-customize-control-<?php echo $this->type; ?>-content">
     520                        <?php $this->content_template(); ?>
     521                </script>
     522                <?php
    523523        }
    524524
    525525        /**
  • src/wp-includes/class-wp-customize-manager.php

    diff --git src/wp-includes/class-wp-customize-manager.php src/wp-includes/class-wp-customize-manager.php
    index b695271..6c9ce4f 100644
    final class WP_Customize_Manager { 
    5454        protected $customized;
    5555
    5656        /**
    57          * Controls that may be rendered from JS templates.
     57         * Panel types that may be rendered from JS templates.
     58         *
     59         * @since 4.2.0
     60         * @access protected
     61         * @var array
     62         */
     63        protected $registered_panel_types = array();
     64
     65        /**
     66         * Section types that may be rendered from JS templates.
     67         *
     68         * @since 4.2.0
     69         * @access protected
     70         * @var array
     71         */
     72        protected $registered_section_types = array();
     73
     74        /**
     75         * Control types that may be rendered from JS templates.
    5876         *
    5977         * @since 4.1.0
    6078         * @access protected
    final class WP_Customize_Manager { 
    513531                }
    514532
    515533                foreach ( $this->settings as $id => $setting ) {
    516                         $settings['values'][ $id ] = $setting->js_value();
     534                        if ( $setting->check_capabilities() ) {
     535                                $settings['values'][ $id ] = $setting->js_value();
     536                        }
    517537                }
    518                 foreach ( $this->panels as $id => $panel ) {
    519                         $settings['activePanels'][ $id ] = $panel->active();
    520                         foreach ( $panel->sections as $id => $section ) {
    521                                 $settings['activeSections'][ $id ] = $section->active();
     538                foreach ( $this->panels as $panel_id => $panel ) {
     539                        if ( $panel->check_capabilities() ) {
     540                                $settings['activePanels'][ $panel_id ] = $panel->active();
     541                                foreach ( $panel->sections as $section_id => $section ) {
     542                                        if ( $section->check_capabilities() ) {
     543                                                $settings['activeSections'][ $section_id ] = $section->active();
     544                                        }
     545                                }
    522546                        }
    523547                }
    524548                foreach ( $this->sections as $id => $section ) {
    525                         $settings['activeSections'][ $id ] = $section->active();
     549                        if ( $section->check_capabilities() ) {
     550                                $settings['activeSections'][ $id ] = $section->active();
     551                        }
    526552                }
    527553                foreach ( $this->controls as $id => $control ) {
    528                         $settings['activeControls'][ $id ] = $control->active();
     554                        if ( $control->check_capabilities() ) {
     555                                $settings['activeControls'][ $id ] = $control->active();
     556                        }
    529557                }
    530558
    531559                ?>
    final class WP_Customize_Manager { 
    774802        }
    775803
    776804        /**
     805         * Register a customize panel type.
     806         *
     807         * Registered types are eligible to be rendered via JS and created dynamically.
     808         *
     809         * @since 4.2.0
     810         * @access public
     811         *
     812         * @param string $panel Name of a custom panel which is a subclass of
     813         *                        {@see WP_Customize_Panel}.
     814         */
     815        public function register_panel_type( $panel ) {
     816                $this->registered_panel_types[] = $panel;
     817        }
     818
     819        /**
     820         * Render JS templates for all registered panel types.
     821         *
     822         * @since 4.2.0
     823         * @access public
     824         */
     825        public function render_panel_templates() {
     826                foreach ( $this->registered_panel_types as $panel_type ) {
     827                        $panel = new $panel_type( $this, 'temp', array() );
     828                        $panel->print_template();
     829                }
     830        }
     831
     832        /**
    777833         * Add a customize section.
    778834         *
    779835         * @since 3.4.0
    final class WP_Customize_Manager { 
    815871        }
    816872
    817873        /**
     874         * Register a customize section type.
     875         *
     876         * Registered types are eligible to be rendered via JS and created dynamically.
     877         *
     878         * @since 4.2.0
     879         * @access public
     880         *
     881         * @param string $section Name of a custom section which is a subclass of
     882         *                        {@see WP_Customize_Section}.
     883         */
     884        public function register_section_type( $section ) {
     885                $this->registered_section_types[] = $section;
     886        }
     887
     888        /**
     889         * Render JS templates for all registered section types.
     890         *
     891         * @since 4.2.0
     892         * @access public
     893         */
     894        public function render_section_templates() {
     895                foreach ( $this->registered_section_types as $section_type ) {
     896                        $section = new $section_type( $this, 'temp', array() );
     897                        $section->print_template();
     898                }
     899        }
     900
     901        /**
    818902         * Add a customize control.
    819903         *
    820904         * @since 3.4.0
    final class WP_Customize_Manager { 
    9851069         */
    9861070        public function register_controls() {
    9871071
    988                 /* Control Types (custom control classes) */
     1072                /* Panel, Section, and Control Types */
     1073                $this->register_panel_type( 'WP_Customize_Panel' );
     1074                $this->register_section_type( 'WP_Customize_Section' );
     1075                $this->register_section_type( 'WP_Customize_Sidebar_Section' );
    9891076                $this->register_control_type( 'WP_Customize_Color_Control' );
    9901077                $this->register_control_type( 'WP_Customize_Upload_Control' );
    9911078                $this->register_control_type( 'WP_Customize_Image_Control' );
  • src/wp-includes/class-wp-customize-panel.php

    diff --git src/wp-includes/class-wp-customize-panel.php src/wp-includes/class-wp-customize-panel.php
    index eed0572..a76be68 100644
    class WP_Customize_Panel { 
    204204         * @return array The array to be exported to the client as JSON.
    205205         */
    206206        public function json() {
    207                 $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'type' ) );
     207                $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'type' ) );
    208208                $array['content'] = $this->get_content();
    209209                $array['active'] = $this->active();
    210210                $array['instanceNumber'] = $this->instance_number;
    class WP_Customize_Panel { 
    279279        }
    280280
    281281        /**
    282          * Render the panel container, and then its contents.
     282         * Render the panel container, and then its contents (via `this->render_content()`) in a subclass.
     283         *
     284         * Panel containers are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}.
    283285         *
    284286         * @since 4.0.0
    285287         * @access protected
    286288         */
    287         protected function render() {
    288                 $classes = 'accordion-section control-section control-panel control-panel-' . $this->type;
     289        protected function render() {}
     290
     291        /**
     292         * Render the panel UI in a subclass.
     293         *
     294         * Panel contents are now rendered in JS by default, see {@see WP_Customize_Panel::print_template()}.
     295         *
     296         * @since 4.1.0
     297         * @access protected
     298         */
     299        protected function render_content() {}
     300
     301        /**
     302         * Render the panel's JS templates.
     303         *
     304         * This function is only run for panel types that have been registered with
     305         * {@see WP_Customize_Manager::register_panel_type()}.
     306         *
     307         * @since 4.2.0
     308         */
     309        public function print_template() {
    289310                ?>
    290                 <li id="accordion-panel-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     311                <script type="text/html" id="tmpl-customize-panel-<?php echo $this->type; ?>-content">
     312                        <?php $this->content_template(); ?>
     313                </script>
     314                <script type="text/html" id="tmpl-customize-panel-<?php echo $this->type; ?>">
     315                        <?php $this->render_template(); ?>
     316                </script>
     317        <?php
     318        }
     319
     320        /**
     321         * An Underscore (JS) template for rendering this panel's container.
     322         *
     323         * Class variables for this panel class are available in the `data` JS object;
     324         * export custom variables by overriding {@see WP_Customize_Panel::json()}.
     325         *
     326         * @see WP_Customize_Panel::print_template()
     327         *
     328         * @since 4.2.0
     329         */
     330        protected function render_template() {
     331                ?>
     332                <li id="accordion-panel-{{ data.id }}" class="accordion-section control-section control-panel control-panel-{{ data.type }}">
    291333                        <h3 class="accordion-section-title" tabindex="0">
    292                                 <?php echo esc_html( $this->title ); ?>
     334                                {{ data.title }}
    293335                                <span class="screen-reader-text"><?php _e( 'Press return or enter to open this panel' ); ?></span>
    294336                        </h3>
    295                         <ul class="accordion-sub-container control-panel-content">
    296                                 <?php $this->render_content(); ?>
    297                         </ul>
     337                        <ul class="accordion-sub-container control-panel-content"></ul>
    298338                </li>
    299339                <?php
    300340        }
    301341
    302342        /**
    303          * Render the sections that have been added to the panel.
     343         * An Underscore (JS) template for this panel's content (but not its container).
    304344         *
    305          * @since 4.1.0
    306          * @access protected
     345         * Class variables for this panel class are available in the `data` JS object;
     346         * export custom variables by overriding {@see WP_Customize_Panel::json()}.
     347         *
     348         * @see WP_Customize_Panel::print_template()
     349         *
     350         * @since 4.2.0
    307351         */
    308         protected function render_content() {
     352        protected function content_template() {
    309353                ?>
    310                 <li class="panel-meta accordion-section control-section<?php if ( empty( $this->description ) ) { echo ' cannot-expand'; } ?>">
     354                <li class="panel-meta accordion-section control-section<# if ( ! data.description ) { #> cannot-expand<# } #>">
    311355                        <div class="accordion-section-title" tabindex="0">
    312356                                <span class="preview-notice"><?php
    313357                                        /* translators: %s is the site/panel title in the Customizer */
    314                                         echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">' . esc_html( $this->title ) . '</strong>' );
     358                                        echo sprintf( __( 'You are customizing %s' ), '<strong class="panel-title">{{ data.title }}</strong>' );
    315359                                ?></span>
    316360                        </div>
    317                         <?php if ( ! empty( $this->description ) ) : ?>
     361                        <# if ( data.description ) { #>
    318362                                <div class="accordion-section-content description">
    319                                         <?php echo $this->description; ?>
     363                                        {{{ data.description }}}
    320364                                </div>
    321                         <?php endif; ?>
     365                        <# } #>
    322366                </li>
    323367                <?php
    324368        }
  • src/wp-includes/class-wp-customize-section.php

    diff --git src/wp-includes/class-wp-customize-section.php src/wp-includes/class-wp-customize-section.php
    index 7d65689..ac7117e 100644
    class WP_Customize_Section { 
    213213         * @return array The array to be exported to the client as JSON.
    214214         */
    215215        public function json() {
    216                 $array = wp_array_slice_assoc( (array) $this, array( 'title', 'description', 'priority', 'panel', 'type' ) );
     216                $array = wp_array_slice_assoc( (array) $this, array( 'id', 'title', 'description', 'priority', 'panel', 'type' ) );
    217217                $array['content'] = $this->get_content();
    218218                $array['active'] = $this->active();
    219219                $array['instanceNumber'] = $this->instance_number;
    class WP_Customize_Section { 
    241241        }
    242242
    243243        /**
    244          * Get the section's content template for insertion into the Customizer pane.
     244         * Get the section's content for insertion into the Customizer pane.
    245245         *
    246246         * @since 4.1.0
    247247         *
    class WP_Customize_Section { 
    287287        }
    288288
    289289        /**
    290          * Render the section, and the controls that have been added to it.
     290         * Render the section UI in a subclass.
     291         *
     292         * Sections are now rendered in JS by default, see {@see WP_Customize_Section::print_template()}.
    291293         *
    292294         * @since 3.4.0
    293295         */
    294         protected function render() {
    295                 $classes = 'accordion-section control-section control-section-' . $this->type;
     296        protected function render() {}
     297
     298        /**
     299         * Render the section's JS template.
     300         *
     301         * This function is only run for section types that have been registered with
     302         * {@see WP_Customize_Manager::register_section_type()}.
     303         *
     304         * @since 4.2.0
     305         */
     306        public function print_template() {
     307        ?>
     308                <script type="text/html" id="tmpl-customize-section-<?php echo $this->type; ?>">
     309                        <?php $this->render_template(); ?>
     310                </script>
     311        <?php
     312        }
     313
     314        /**
     315         * An Underscore (JS) template for rendering this section.
     316         *
     317         * Class variables for this section class are available in the `data` JS object;
     318         * export custom variables by overriding {@see WP_Customize_Section::json()}.
     319         *
     320         * @see WP_Customize_Section::print_template()
     321         *
     322         * @since 4.2.0
     323         */
     324        protected function render_template() {
    296325                ?>
    297                 <li id="accordion-section-<?php echo esc_attr( $this->id ); ?>" class="<?php echo esc_attr( $classes ); ?>">
     326                <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}">
    298327                        <h3 class="accordion-section-title" tabindex="0">
    299                                 <?php echo esc_html( $this->title ); ?>
     328                                {{ data.title }}
    300329                                <span class="screen-reader-text"><?php _e( 'Press return or enter to expand' ); ?></span>
    301330                        </h3>
    302331                        <ul class="accordion-section-content">
    303                                 <?php if ( ! empty( $this->description ) ) : ?>
     332                                <# if ( data.description ) { #>
    304333                                        <li class="customize-section-description-container">
    305                                                 <p class="description customize-section-description"><?php echo $this->description; ?></p>
     334                                                <p class="description customize-section-description">{{{ data.description }}}</p>
    306335                                        </li>
    307                                 <?php endif; ?>
     336                                <# } #>
    308337                        </ul>
    309338                </li>
    310339                <?php