Make WordPress Core


Ignore:
Timestamp:
03/15/2023 11:36:52 AM (20 months ago)
Author:
spacedmonkey
Message:

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.

File:
1 edited

Legend:

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

    r55276 r55553  
    6969        }
    7070        $this->registered = true;
    71 
    72         wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
    7371
    7472        // Note that the widgets component in the customizer will also do
     
    217215
    218216        wp_enqueue_script( 'custom-html-widgets' );
     217        wp_add_inline_script( 'custom-html-widgets', sprintf( 'wp.customHtmlWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
     218
    219219        if ( empty( $settings ) ) {
    220220            $settings = array(
Note: See TracChangeset for help on using the changeset viewer.