Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Editor Bindings

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 📦

Understanding the Example Code

Editor Bindings Example Screenshot

Some key ideas for this example:

  • Custom Binding Source Registration: The plugin registers a block-dev-ex/post-data binding 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/blocks and 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 postId context 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

Related resources


Note Check the Start Guide for local development with the examples