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. git-svn-id: https://develop.svn.wordpress.org/trunk@41028 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
1c017250b7
commit
6daeb23005
@ -33,6 +33,14 @@ abstract class WP_Widget_Media extends WP_Widget {
|
|||||||
'add_media' => '',
|
'add_media' => '',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the widget has been registered yet.
|
||||||
|
*
|
||||||
|
* @since 4.8.1
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $registered = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
@ -86,8 +94,16 @@ abstract class WP_Widget_Media extends WP_Widget {
|
|||||||
*
|
*
|
||||||
* @since 4.8.0
|
* @since 4.8.0
|
||||||
* @access public
|
* @access public
|
||||||
|
*
|
||||||
|
* @param integer $number Optional. The unique order number of this widget instance
|
||||||
|
* compared to other instances of the same class. Default -1.
|
||||||
*/
|
*/
|
||||||
public function _register() {
|
public function _register_one( $number = -1 ) {
|
||||||
|
parent::_register_one( $number );
|
||||||
|
if ( $this->registered ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->registered = true;
|
||||||
|
|
||||||
// Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
|
// Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
|
||||||
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
|
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
|
||||||
@ -100,8 +116,6 @@ abstract class WP_Widget_Media extends WP_Widget {
|
|||||||
add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
|
add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
|
||||||
|
|
||||||
add_filter( 'display_media_states', array( $this, 'display_media_state' ), 10, 2 );
|
add_filter( 'display_media_states', array( $this, 'display_media_state' ), 10, 2 );
|
||||||
|
|
||||||
parent::_register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -16,6 +16,14 @@
|
|||||||
*/
|
*/
|
||||||
class WP_Widget_Text extends WP_Widget {
|
class WP_Widget_Text extends WP_Widget {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether or not the widget has been registered yet.
|
||||||
|
*
|
||||||
|
* @since 4.8.1
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $registered = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up a new Text widget instance.
|
* Sets up a new Text widget instance.
|
||||||
*
|
*
|
||||||
@ -38,18 +46,21 @@ class WP_Widget_Text extends WP_Widget {
|
|||||||
/**
|
/**
|
||||||
* Add hooks for enqueueing assets when registering all widget instances of this widget class.
|
* Add hooks for enqueueing assets when registering all widget instances of this widget class.
|
||||||
*
|
*
|
||||||
* @since 4.8.0
|
* @param integer $number Optional. The unique order number of this widget instance
|
||||||
* @access public
|
* compared to other instances of the same class. Default -1.
|
||||||
*/
|
*/
|
||||||
public function _register() {
|
public function _register_one( $number = -1 ) {
|
||||||
|
parent::_register_one( $number );
|
||||||
|
if ( $this->registered ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$this->registered = true;
|
||||||
|
|
||||||
// Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
|
// Note that the widgets component in the customizer will also do the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
|
||||||
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
|
add_action( 'admin_print_scripts-widgets.php', array( $this, 'enqueue_admin_scripts' ) );
|
||||||
|
|
||||||
// Note that the widgets component in the customizer will also do the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
|
// Note that the widgets component in the customizer will also do the 'admin_footer-widgets.php' action in WP_Customize_Widgets::print_footer_scripts().
|
||||||
add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
|
add_action( 'admin_footer-widgets.php', array( $this, 'render_control_template_scripts' ) );
|
||||||
|
|
||||||
parent::_register();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user