Make WordPress Core


Ignore:
Timestamp:
03/15/2023 11:36:52 AM (21 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-text.php

    r55276 r55553  
    5656        }
    5757        $this->registered = true;
    58 
    59         wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
    6058
    6159        if ( $this->is_preview() ) {
     
    437435        wp_enqueue_media();
    438436        wp_enqueue_script( 'text-widgets' );
     437        wp_add_inline_script( 'text-widgets', sprintf( 'wp.textWidgets.idBases.push( %s );', wp_json_encode( $this->id_base ) ) );
    439438        wp_add_inline_script( 'text-widgets', 'wp.textWidgets.init();', 'after' );
    440439    }
Note: See TracChangeset for help on using the changeset viewer.