Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use global variable in wp_script_modules() #5945

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/wp-includes/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,31 @@ class WP_Script_Modules {
*/
private $enqueued_before_registered = array();

/**
* Container for the main instance of the class.
*
* @since 6.5.0
* @var WP_Script_Modules|null
*/
private static $instance = null;

/**
* Utility method to retrieve the main instance of the class.
*
* The instance will be created if it does not exist yet.
*
* @since 6.5.0
*
* @return WP_Script_Modules The main instance.
*/
public static function get_instance(): WP_Script_Modules {
if ( null === self::$instance ) {
self::$instance = new self();
}

return self::$instance;
}

swissspidy marked this conversation as resolved.
Show resolved Hide resolved
/**
* Registers the script module if no script module with that script module
* identifier has already been registered.
Expand Down
7 changes: 1 addition & 6 deletions src/wp-includes/script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@
* @return WP_Script_Modules The main WP_Script_Modules instance.
*/
function wp_script_modules(): WP_Script_Modules {
static $instance = null;
if ( is_null( $instance ) ) {
$instance = new WP_Script_Modules();
$instance->add_hooks();
}
return $instance;
return WP_Script_Modules::get_instance();
swissspidy marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/wp-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@
require ABSPATH . WPINC . '/script-modules.php';
require ABSPATH . WPINC . '/interactivity-api.php';

wp_script_modules()->add_hooks();

$GLOBALS['wp_embed'] = new WP_Embed();

/**
Expand Down
Loading