This example is taken from the following WordPress Developer Blog post:
| Example | Description | Tags | Download .zip | Live Demo |
|---|---|---|---|---|
| Editor Bindings | Shows how to create a block that uses editor bindings to connect custom fields to the block editor. | block-bindings |
📦 |
Some key ideas for this example:
- Custom Binding Source Registration: The plugin registers a
block-dev-ex/post-databinding source both server-side (register_block_bindings_source()) and client-side (registerBlockBindingsSource()) - Dynamic Data Access: The binding source provides access to post title, excerpt, and permalink through the Block Bindings API
- Editor Integration: Uses WordPress Data API (
@wordpress/blocksand editor store) to fetch and update post data in real-time - Controlled Editability: Implements
canUserEditValue()to make title and excerpt editable while keeping permalink read-only - Context-Aware: Uses
postIdcontext to determine which post's data to fetch and display - WordPress 6.9+ UI Integration: Implements
getFieldsList()to expose binding fields (Title, Excerpt, Permalink) in the editor's Block Bindings dropdown interface, allowing users to easily connect block attributes to custom data sources
- Block Bindings API documentation
registerBlockBindingsSourcedocumentation- Block Bindings improvements in WordPress 6.9
Note Check the Start Guide for local development with the examples
