Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add uses_context to editor settings
  • Loading branch information
SantosGuillamot committed Sep 20, 2024
commit 0e5fb3506c2bcbb914b30be0c5d9bc030850e92c
3 changes: 3 additions & 0 deletions src/wp-includes/block-bindings.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,3 +129,6 @@ function get_all_registered_block_bindings_sources() {
function get_block_bindings_source( string $source_name ) {
return WP_Block_Bindings_Registry::get_instance()->get_registered( $source_name );
}

// Add the `uses_context` to the block editor settings to ensure it can be consumed in the client.
add_filter( 'block_editor_settings_all', array( 'WP_Block_Bindings_Registry', 'add_uses_context_to_editor_settings' ), 10 );
20 changes: 20 additions & 0 deletions src/wp-includes/class-wp-block-bindings-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,24 @@ public static function get_instance() {

return self::$instance;
}

/**
* Adds the `uses_context` to the editor settings.
*
* This allows to reuse the `uses_context` definition in the editor.
*
* @since 6.6.0
*
* @param array $settings The block editor settings from the `block_editor_settings_all` filter.
* @return array The editor settings with extended block bindings `uses_context`.
*/
public static function add_uses_context_to_editor_settings( $settings ) {
$registered_block_bindings_sources = get_all_registered_block_bindings_sources();
foreach ( $registered_block_bindings_sources as $source ) {
if ( ! empty( $source->uses_context ) ) {
$settings['__experimentalBlockBindings'][ $source->name ]['usesContext'] = $source->uses_context;
}
}
return $settings;
}
}