mirror of
https://github.com/WordPress/WordPress.git
synced 2025-02-23 07:51:49 +01:00
Widgets: Defer register inline script in WP_Widget_Custom_HTML
and WP_Widget_Text
.
In [41376] an inline script was added to push `idBases` for the custom html and text widgets. However, this script is not used unless the widget script is output in the widget screen / customizer. Deferring registering this script until it is needed, results in a faster server response times. Props spacedmonkey, sakibmd, flixos90, westonruter. Fixes #57864. Built from https://develop.svn.wordpress.org/trunk@55553 git-svn-id: http://core.svn.wordpress.org/trunk@55065 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
26852dbac7
commit
d409e8ad50
@ -16,7 +16,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.3-alpha-55552';
|
$wp_version = '6.3-alpha-55553';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
@ -69,8 +69,6 @@ class WP_Widget_Custom_HTML extends WP_Widget {
|
|||||||
}
|
}
|
||||||
$this->registered = true;
|
$this->registered = true;
|
||||||
|
|
||||||
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
|
|
||||||
|
|
||||||
// Note that the widgets component in the customizer will also do
|
// Note that the widgets component in the customizer will also do
|
||||||
// the 'admin_print_scripts-widgets.php' action in WP_Customize_Widgets::print_scripts().
|
// 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' ) );
|
||||||
@ -216,6 +214,8 @@ class WP_Widget_Custom_HTML extends WP_Widget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
wp_enqueue_script( 'custom-html-widgets' );
|
wp_enqueue_script( 'custom-html-widgets' );
|
||||||
|
wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
|
||||||
|
|
||||||
if ( empty( $settings ) ) {
|
if ( empty( $settings ) ) {
|
||||||
$settings = array(
|
$settings = array(
|
||||||
'disabled' => true,
|
'disabled' => true,
|
||||||
|
@ -56,8 +56,6 @@ class WP_Widget_Text extends WP_Widget {
|
|||||||
}
|
}
|
||||||
$this->registered = true;
|
$this->registered = true;
|
||||||
|
|
||||||
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
|
|
||||||
|
|
||||||
if ( $this->is_preview() ) {
|
if ( $this->is_preview() ) {
|
||||||
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
|
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_preview_scripts' ) );
|
||||||
}
|
}
|
||||||
@ -436,6 +434,7 @@ class WP_Widget_Text extends WP_Widget {
|
|||||||
wp_enqueue_editor();
|
wp_enqueue_editor();
|
||||||
wp_enqueue_media();
|
wp_enqueue_media();
|
||||||
wp_enqueue_script( 'text-widgets' );
|
wp_enqueue_script( 'text-widgets' );
|
||||||
|
wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
|
||||||
wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
|
wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user