Make WordPress Core


Ignore:
Timestamp:
07/11/2017 10:46:45 PM (9 years ago)
Author:
westonruter
Message:

Widgets: Enqueue assets needed by media and text widgets in their _register_one() methods.

The WP_Widget::_register_one() method is more guaranteed to be called as opposed to its wrapper WP_Widget::_register() which plugins may bypass for performance reasons.

Amends [40631], [40640].
See #35243, #32417.
Fixes #41021.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/widgets/class-wp-widget-media.php

    r40812 r41028  
    3333                'add_media' => '',
    3434        );
     35
     36        /**
     37         * Whether or not the widget has been registered yet.
     38         *
     39         * @since 4.8.1
     40         * @var bool
     41         */
     42        protected $registered = false;
    3543
    3644        /**
     
    8795         * @since 4.8.0
    8896         * @access public
    89          */
    90         public function _register() {
     97         *
     98         * @param integer $number Optional. The unique order number of this widget instance
     99         *                        compared to other instances of the same class. Default -1.
     100         */
     101        public function _register_one( $number = -1 ) {
     102                parent::_register_one( $number );
     103                if ( $this->registered ) {
     104                        return;
     105                }
     106                $this->registered = true;
    91107
    92108                // Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
     
    101117
    102118                add_filter( 'display_media_states', array( $this, 'display_media_state' ), 10, 2 );
    103 
    104                 parent::_register();
    105119        }
    106120
Note: See TracChangeset for help on using the changeset viewer.