Skip to content

Commit

Permalink
Add uses_context to editor settings
Browse files Browse the repository at this point in the history
  • Loading branch information
SantosGuillamot committed May 14, 2024
1 parent 8035804 commit 18c83aa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
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;
}
}

0 comments on commit 18c83aa

Please sign in to comment.