Make WordPress Core


Ignore:
Timestamp:
01/31/2024 06:14:30 PM (12 months ago)
Author:
swissspidy
Message:

Script Loader: Use a global variable in wp_script_modules().

This brings the function more in line with its related wp_scripts() and wp_styles() functions and makes it easier to reset the class instance in tests.

Props westonruter, luisherranz.
See #56313.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-modules.php

    r57327 r57503  
    1515 * if it doesn't exist yet.
    1616 *
     17 * @global WP_Script_Modules $wp_script_modules
     18 *
    1719 * @since 6.5.0
    1820 *
     
    2022 */
    2123function wp_script_modules(): WP_Script_Modules {
    22     static $instance = null;
    23     if ( is_null( $instance ) ) {
    24         $instance = new WP_Script_Modules();
    25         $instance->add_hooks();
     24    global $wp_script_modules;
     25
     26    if ( ! ( $wp_script_modules instanceof WP_Script_Modules ) ) {
     27        $wp_script_modules = new WP_Script_Modules();
    2628    }
    27     return $instance;
     29
     30    return $wp_script_modules;
    2831}
    2932
Note: See TracChangeset for help on using the changeset viewer.