WordPress.org

Make WordPress Core

Changeset 27907


Ignore:
Timestamp:
04/02/2014 05:03:14 PM (4 years ago)
Author:
ocean90
Message:

Widget Customizer: Improve plugin compatibility.

Some plugins are using custom scripts and styles for there widgets. These are available on the Widgets screens, but not in the Customizer yet.
Scripts and styles can be enqueued via:

  • admin_enqueue_scripts
  • admin_print_scripts and admin_print_scripts-widgets.php
  • admin_print_styles and admin_print_styles-widgets.php
  • admin_print_footer_scripts and admin_footer-widgets.php

All this hooks are now called in the Customizer too.

Previously we have add the #widgets-right ID to a container div via jQuery. Remember: #widgets-right exists on the Widgets screen and is used by many plugins to do event delegation from that element.
But since our script files are loaded in the footer, the JavaScript way is a bit late for some plugins.
We have decided to add a div#widgets-right container element to customizer. "Less hacky hack."

props westonruter, ocean90. Thanks dpe415 for testing.
fixes #27619.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/customize.php

    r27695 r27907  
    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'; ?>">
     
    147148            </ul></div>
    148149        </div>
     150        </div>
    149151
    150152        <div id="customize-footer-actions" class="wp-full-overlay-footer">
  • trunk/src/wp-admin/js/customize-widgets.js

    r27893 r27907  
    3535        window.ajaxurl = wp.ajax.settings.url;
    3636    }
    37 
    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' );
    4137
    4238    /**
  • trunk/src/wp-includes/class-wp-customize-widgets.php

    r27904 r27907  
    7575        add_action( 'customize_controls_init',                 array( $this, 'customize_controls_init' ) );
    7676        add_action( 'customize_register',                      array( $this, 'schedule_customize_register' ), 1 );
    77         add_action( 'customize_controls_enqueue_scripts',      array( $this, 'customize_controls_enqueue_deps' ) );
     77        add_action( 'customize_controls_enqueue_scripts',      array( $this, 'enqueue_scripts' ) );
     78        add_action( 'customize_controls_print_styles',         array( $this, 'print_styles' ) );
     79        add_action( 'customize_controls_print_scripts',        array( $this, 'print_scripts' ) );
     80        add_action( 'customize_controls_print_footer_scripts', array( $this, 'print_footer_scripts' ) );
    7881        add_action( 'customize_controls_print_footer_scripts', array( $this, 'output_widget_control_templates' ) );
    7982        add_action( 'customize_preview_init',                  array( $this, 'customize_preview_init' ) );
     
    534537
    535538    /**
     539     * Call admin_print_styles-widgets.php and admin_print_styles hooks to
     540     * allow custom styles from plugins.
     541     *
     542     * @since 3.9.0
     543     * @access public
     544     */
     545    public function print_styles() {
     546        /** This action is documented in wp-admin/admin-header.php */
     547        do_action( 'admin_print_styles-widgets.php' );
     548
     549        /** This action is documented in wp-admin/admin-header.php */
     550        do_action( 'admin_print_styles' );
     551    }
     552
     553    /**
     554     * Call admin_print_scripts-widgets.php and admin_print_scripts hooks to
     555     * allow custom scripts from plugins.
     556     *
     557     * @since 3.9.0
     558     * @access public
     559     */
     560    public function print_scripts() {
     561        /** This action is documented in wp-admin/admin-header.php */
     562        do_action( 'admin_print_scripts-widgets.php' );
     563
     564        /** This action is documented in wp-admin/admin-header.php */
     565        do_action( 'admin_print_scripts' );
     566    }
     567
     568    /**
    536569     * Enqueue scripts and styles for customizer panel and export data to JavaScript.
    537570     *
     
    539572     * @access public
    540573     */
    541     public function customize_controls_enqueue_deps() {
     574    public function enqueue_scripts() {
    542575        wp_enqueue_style( 'customize-widgets' );
    543576        wp_enqueue_script( 'customize-widgets' );
     577
     578        /** This action is documented in wp-admin/admin-header.php */
     579        do_action( 'admin_enqueue_scripts', 'widgets.php' );
    544580
    545581        /*
     
    643679
    644680    /**
     681     * Call admin_print_footer_scripts and admin_print_scripts hooks to
     682     * allow custom scripts from plugins.
     683     *
     684     * @since 3.9.0
     685     * @access public
     686     */
     687    public function print_footer_scripts() {
     688        /** This action is documented in wp-admin/admin-footer.php */
     689        do_action( 'admin_print_footer_scripts' );
     690
     691        /** This action is documented in wp-admin/admin-footer.php */
     692        do_action( 'admin_footer-widgets.php' );
     693    }
     694
     695    /**
    645696     * Get common arguments to supply when constructing a Customizer setting.
    646697     *
Note: See TracChangeset for help on using the changeset viewer.