From 16051481515ac641bd51afca344939abdfd21c97 Mon Sep 17 00:00:00 2001 From: Carlos Bravo <37012961+c4rl0sbr4v0@users.noreply.github.com> Date: Mon, 19 Feb 2024 09:23:42 +0100 Subject: [PATCH] Modules API: Script Modules add deregister option. (#58830) * Add deregister module function * Sync with core PR --- .../wordpress-6.5/class-wp-script-modules.php | 12 +++++++ lib/compat/wordpress-6.5/scripts-modules.php | 13 ++++++++ lib/experimental/interactivity-api.php | 22 ------------- lib/interactivity-api.php | 32 +++++++++++++++++++ lib/load.php | 2 +- 5 files changed, 58 insertions(+), 23 deletions(-) delete mode 100644 lib/experimental/interactivity-api.php create mode 100644 lib/interactivity-api.php diff --git a/lib/compat/wordpress-6.5/class-wp-script-modules.php b/lib/compat/wordpress-6.5/class-wp-script-modules.php index 205b50cd532596..4d3280f1db0b97 100644 --- a/lib/compat/wordpress-6.5/class-wp-script-modules.php +++ b/lib/compat/wordpress-6.5/class-wp-script-modules.php @@ -152,6 +152,18 @@ public function dequeue( string $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 * module preloads. diff --git a/lib/compat/wordpress-6.5/scripts-modules.php b/lib/compat/wordpress-6.5/scripts-modules.php index 8fd8978d9e8f5d..c4a1690b6986f0 100644 --- a/lib/compat/wordpress-6.5/scripts-modules.php +++ b/lib/compat/wordpress-6.5/scripts-modules.php @@ -207,3 +207,16 @@ function wp_dequeue_script_module( string $id ) { wp_script_modules()->dequeue( $id ); } } + +if ( ! function_exists( 'wp_deregister_script_module' ) ) { + /** + * 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 ); + } +} diff --git a/lib/experimental/interactivity-api.php b/lib/experimental/interactivity-api.php deleted file mode 100644 index 5d0f694dca3692..00000000000000 --- a/lib/experimental/interactivity-api.php +++ /dev/null @@ -1,22 +0,0 @@ -