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

Modules API: Script Modules add deregister option. #58830

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions lib/compat/wordpress-6.5/class-wp-script-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions lib/compat/wordpress-6.5/scripts-modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
}
22 changes: 0 additions & 22 deletions lib/experimental/interactivity-api.php

This file was deleted.

32 changes: 32 additions & 0 deletions lib/interactivity-api.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Interactivity API functions specific for the Gutenberg editor plugin.
*
* @package gutenberg
*/

/**
* Deregisters the Core Interactivity API Modules and replace them
* with the ones from the Gutenberg plugin.
*/
function gutenberg_reregister_interactivity_script_modules() {
$default_version = defined( 'GUTENBERG_VERSION' ) && ! SCRIPT_DEBUG ? GUTENBERG_VERSION : time();
wp_deregister_script_module( '@wordpress/interactivity' );
wp_deregister_script_module( '@wordpress/interactivity-router' );

wp_register_script_module(
'@wordpress/interactivity',
gutenberg_url( '/build/interactivity/index.min.js' ),
array(),
$default_version
);

wp_register_script_module(
'@wordpress/interactivity-router',
gutenberg_url( '/build/interactivity/router.min.js' ),
array( '@wordpress/interactivity' ),
$default_version
);
}

add_action( 'init', 'gutenberg_reregister_interactivity_script_modules' );
2 changes: 1 addition & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/l10n.php';
require __DIR__ . '/experimental/synchronization.php';
require __DIR__ . '/experimental/script-modules.php';
require __DIR__ . '/experimental/interactivity-api.php';

if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
require __DIR__ . '/experimental/disable-tinymce.php';
Expand Down Expand Up @@ -192,6 +191,7 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/client-assets.php';
require __DIR__ . '/demo.php';
require __DIR__ . '/experiments-page.php';
require __DIR__ . '/interactivity-api.php';

// Copied package PHP files.
if ( is_dir( __DIR__ . '/../build/style-engine' ) ) {
Expand Down