Skip to content

Commit

Permalink
Add compat filter in Gutenberg
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed Oct 11, 2024
1 parent 1945be1 commit e81d827
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/compat/wordpress-6.7/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,30 @@
* @package gutenberg
*/

/**
* Bootstrap the block bindings sources registered in the server.
*/
function gutenberg_bootstrap_server_block_bindings_sources() {
$registered_sources = get_all_registered_block_bindings_sources();
if ( ! empty( $registered_sources ) ) {
$filtered_sources = array();
foreach ( $registered_sources as $source ) {
$filtered_sources[] = array(
'name' => $source->name,
'label' => $source->label,
'usesContext' => $source->uses_context,
);
}
$script = sprintf( 'for ( const source of %s ) { wp.blocks.registerBlockBindingsSource( source ); }', wp_json_encode( $filtered_sources ) );
wp_add_inline_script(
'wp-blocks',
$script
);
}
}

add_action( 'enqueue_block_editor_assets', 'gutenberg_bootstrap_server_block_bindings_sources', 5 );

/**
* Initialize `canUpdateBlockBindings` editor setting if it doesn't exist. By default, it is `true` only for admin users.
*
Expand Down

0 comments on commit e81d827

Please sign in to comment.