Skip to content

Commit

Permalink
Fix Gutenberg breaking backward compatibility: AJAX script must be re…
Browse files Browse the repository at this point in the history
…gistered twice to support enqueue inside iframe

- [Block Editor: Enqueueing Assets in the Editor](https://developer.wordpress.org/block-editor/how-to-guides/enqueueing-assets-in-the-editor/#backward-compatibility-and-known-issues)
- [enqueue_block_assets hook loads scripts twice](WordPress/gutenberg#53590)
- Resolves #135
  • Loading branch information
eliot-akira committed Nov 19, 2024
1 parent bd25515 commit 06c2199
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion framework/ajax/enqueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function enqueue() {

function register() {

if (ajax::$state->registered) return;
// if (ajax::$state->registered) return;

wp_deregister_script('tangible-ajax'); // Override previous versions

Expand Down Expand Up @@ -53,9 +53,13 @@ function conditional_enqueue() {
// Register after priority 1, when plugin framework used to register
add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\register', 2);
add_action('admin_enqueue_scripts', __NAMESPACE__ . '\\register', 2);
add_action('enqueue_block_assets', __NAMESPACE__ . '\\register', 2);
add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\\register', 2);

add_action('wp_enqueue_scripts', __NAMESPACE__ . '\\conditional_enqueue', 999);
add_action('admin_enqueue_scripts', __NAMESPACE__ . '\\conditional_enqueue', 999);
add_action('enqueue_block_assets', __NAMESPACE__ . '\\conditional_enqueue', 999);
add_action('enqueue_block_editor_assets', __NAMESPACE__ . '\\conditional_enqueue', 999);

add_action('wp_footer', __NAMESPACE__ . '\\conditional_enqueue', 0);
add_action('admin_footer', __NAMESPACE__ . '\\conditional_enqueue', 0);

0 comments on commit 06c2199

Please sign in to comment.