Script Modules API: Add deregister module function

It was impossible to deregister a script module. It is changing to avoid problems for extenders that want to override any Core script module.

Fixes #60463.
Props cbravobernal, gziolo, mukesh27, youknowriad.


Built from https://develop.svn.wordpress.org/trunk@57593


git-svn-id: http://core.svn.wordpress.org/trunk@57094 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
gziolo 2024-02-12 13:00:10 +00:00
parent c04996591b
commit b0e171fe16
3 changed files with 24 additions and 1 deletions

View File

@ -151,6 +151,18 @@ class WP_Script_Modules {
unset( $this->enqueued_before_registered[ $id ] ); unset( $this->enqueued_before_registered[ $id ] );
} }
/**
* Removes a registered script module.
*
* @since 6.5.0
*
* @param string $id The identifier of the script module.
*/
public function deregister( string $id ) {
unset( $this->registered[ $id ] );
unset( $this->enqueued_before_registered[ $id ] );
}
/** /**
* Adds the hooks to print the import map, enqueued script modules and script * Adds the hooks to print the import map, enqueued script modules and script
* module preloads. * module preloads.

View File

@ -112,3 +112,14 @@ function wp_enqueue_script_module( string $id, string $src = '', array $deps = a
function wp_dequeue_script_module( string $id ) { function wp_dequeue_script_module( string $id ) {
wp_script_modules()->dequeue( $id ); wp_script_modules()->dequeue( $id );
} }
/**
* Deregisters the script module.
*
* @since 6.5.0
*
* @param string $id The identifier of the script module.
*/
function wp_deregister_script_module( string $id ) {
wp_script_modules()->deregister( $id );
}

View File

@ -16,7 +16,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '6.5-alpha-57592'; $wp_version = '6.5-alpha-57593';
/** /**
* 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.