Make WordPress Core


Ignore:
Timestamp:
07/24/2024 10:57:27 AM (2 years ago)
Author:
cbravobernal
Message:

Block Bindings: Adds sources in the editor settings to consume them in the client

Adds a new property blockBindingsSources to the editor settings to expose the block bindings sources registered in the server.

Props santosguillamot, cbravobernal, gziolo, artemiosans.
Fixes #61641.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r58703 r58798  
    647647        if ( isset( $post_content_block_attributes ) ) {
    648648                $editor_settings['postContentAttributes'] = $post_content_block_attributes;
     649        }
     650
     651        // Expose block bindings sources in the editor settings.
     652        $registered_block_bindings_sources = get_all_registered_block_bindings_sources();
     653        if ( ! empty( $registered_block_bindings_sources ) ) {
     654                // Initialize array.
     655                $editor_settings['blockBindingsSources'] = array();
     656                foreach ( $registered_block_bindings_sources as $source_name => $source_properties ) {
     657                        // Add source with the label to editor settings.
     658                        $editor_settings['blockBindingsSources'][ $source_name ] = array(
     659                                'label' => $source_properties->label,
     660                        );
     661                        // Add `usesContext` property if exists.
     662                        if ( ! empty( $source_properties->uses_context ) ) {
     663                                $editor_settings['blockBindingsSources'][ $source_name ]['usesContext'] = $source_properties->uses_context;
     664                        }
     665                }
    649666        }
    650667
Note: See TracChangeset for help on using the changeset viewer.