WordPress.org

Make WordPress Core

Ticket #27619: 27619.2.patch

File 27619.2.patch, 4.9 KB (added by westonruter, 4 years ago)

Add a div#widgets-right container element to customizer for compat with widget scripts that do event delegation from that element; less hacky hack. Do admin_enqueue_scripts after enqueueing customize-widgets. https://github.com/x-team/wordpress-develop/compare/trac-27619

  • src/wp-admin/customize.php

    diff --git src/wp-admin/customize.php src/wp-admin/customize.php
    index d3b09f2..b1485d1 100644
    do_action( 'customize_controls_print_scripts' ); 
    118118                        $cannot_expand = ! ( $screenshot || $wp_customize->theme()->get('Description') );
    119119                ?>
    120120
     121                <div id="widgets-right"><!-- For Widget Customizer, many widgets try to look for instances under div#widgets-right, so we have to add that ID to a container div in the customizer for compat -->
    121122                <div class="wp-full-overlay-sidebar-content accordion-container" tabindex="-1">
    122123                        <div id="customize-info" class="accordion-section <?php if ( $cannot_expand ) echo ' cannot-expand'; ?>">
    123124                                <div class="accordion-section-title" aria-label="<?php esc_attr_e( 'Theme Customizer Options' ); ?>" tabindex="0">
    do_action( 'customize_controls_print_scripts' ); 
    146147                                ?>
    147148                        </ul></div>
    148149                </div>
     150                </div>
    149151
    150152                <div id="customize-footer-actions" class="wp-full-overlay-footer">
    151153                        <a href="#" class="collapse-sidebar button-secondary" title="<?php esc_attr_e('Collapse Sidebar'); ?>">
  • src/wp-admin/js/customize-widgets.js

    diff --git src/wp-admin/js/customize-widgets.js src/wp-admin/js/customize-widgets.js
    index f0c1e8c..b28bba8 100644
    var WidgetCustomizer = ( function ($) { 
    3535                window.ajaxurl = wp.ajax.settings.url;
    3636        }
    3737
    38         // Unfortunately many widgets try to look for instances under div#widgets-right,
    39         // so we have to add that ID to a container div in the customizer for compat
    40         $( '#customize-theme-controls' ).closest( 'div:not([id])' ).attr( 'id', 'widgets-right' );
    41 
    4238        /**
    4339         * Set up model
    4440         */
  • src/wp-includes/class-wp-customize-widgets.php

    diff --git src/wp-includes/class-wp-customize-widgets.php src/wp-includes/class-wp-customize-widgets.php
    index 335181f..e19006b 100644
    final class WP_Customize_Widgets { 
    7878                add_action( 'after_setup_theme',                       array( $this, 'setup_widget_addition_previews' ) );
    7979                add_action( 'customize_controls_init',                 array( $this, 'customize_controls_init' ) );
    8080                add_action( 'customize_register',                      array( $this, 'schedule_customize_register' ), 1 );
    81                 add_action( 'customize_controls_enqueue_scripts',      array( $this, 'customize_controls_enqueue_deps' ) );
     81                add_action( 'customize_controls_enqueue_scripts',      array( $this, 'enqueue_scripts' ) );
     82                add_action( 'customize_controls_print_styles',         array( $this, 'print_styles' ) );
     83                add_action( 'customize_controls_print_scripts',        array( $this, 'print_scripts' ) );
     84                add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_footer_scripts' ) );
    8285                add_action( 'customize_controls_print_footer_scripts', array( $this, 'output_widget_control_templates' ) );
    8386                add_action( 'customize_preview_init',                  array( $this, 'customize_preview_init' ) );
    8487
    final class WP_Customize_Widgets { 
    517520        }
    518521
    519522        /**
     523         * Call admin_print_styles-widgets.php and admin_print_styles hooks.
     524         *
     525         * @since 3.9.0
     526         * @access public
     527         */
     528        public function print_styles() {
     529                /** This action is documented in wp-admin/admin-header.php */
     530                do_action( 'admin_print_styles-widgets.php' );
     531
     532                /** This action is documented in wp-admin/admin-header.php */
     533                do_action( 'admin_print_styles' );
     534        }
     535
     536        /**
     537         * Call admin_print_scripts-widgets.php and admin_print_scripts hooks.
     538         *
     539         * @since 3.9.0
     540         * @access public
     541         */
     542        public function print_scripts() {
     543                /** This action is documented in wp-admin/admin-header.php */
     544                do_action( 'admin_print_scripts-widgets.php' );
     545
     546                /** This action is documented in wp-admin/admin-header.php */
     547                do_action( 'admin_print_scripts' );
     548        }
     549
     550        /**
    520551         * Enqueue scripts and styles for customizer panel and export data to JS.
    521552         *
    522553         * @since 3.9.0
    523554         * @access public
    524555         */
    525         public function customize_controls_enqueue_deps() {
     556        public function enqueue_scripts() {
    526557                wp_enqueue_style( 'customize-widgets' );
    527558                wp_enqueue_script( 'customize-widgets' );
    528559
     560                /** This action is documented in wp-admin/admin-header.php */
     561                do_action( 'admin_enqueue_scripts', 'widgets.php' );
     562
    529563                // Export available widgets with control_tpl removed from model
    530564                // since plugins need templates to be in the DOM
    531565                $available_widgets = array();
    final class WP_Customize_Widgets { 
    594628        }
    595629
    596630        /**
     631         * Call admin_print_footer_scripts and admin_print_scripts hooks.
     632         *
     633         * @since 3.9.0
     634         * @access public
     635         */
     636        public function print_footer_scripts() {
     637                /** This action is documented in wp-admin/admin-footer.php */
     638                do_action( 'admin_print_footer_scripts' );
     639
     640                /** This action is documented in wp-admin/admin-footer.php */
     641                do_action( 'admin_footer-widgets.php' );
     642        }
     643
     644        /**
    597645         * Render the widget form control templates into the DOM so that plugin scripts can manipulate them
    598646         *
    599647         * @since 3.9.0