Expand block bindings support using WordPress core's supported bindings list#715
Expand block bindings support using WordPress core's supported bindings list#715
Conversation
- Add support for core/details block - Add support for dynamic blocks: post-title, post-date, post-excerpt, post-featured-image, post-author - Add support for additional button attributes: linkTarget and rel - Add support for image title attribute - Add filter to allow dynamic registration of bindable blocks - Update BlockBindingControls to handle new blocks and attributes - Update documentation with supported blocks and extension guide Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
|
@copilot this is how you get the list of supported blocks/attributes. You do not need to add another filter to register them with RDB directly. const settings = wp.data.select('core/block-editor').getSettings();
const supportedAttributes = settings.__experimentalBlockBindingsSupportedAttributes;
// e.g. supportedAttributes['core/paragraph'] => ['content']
// e.g. supportedAttributes['core/image'] => ['id', 'url', 'title', 'alt', 'caption'] |
…nstead of hardcoded list Based on feedback, replaced the hardcoded SUPPORTED_CORE_BLOCKS list with a dynamic query to WordPress's block editor settings. This ensures automatic compatibility with all blocks that WordPress designates as supporting bindings, including future additions. - Query __experimentalBlockBindingsSupportedAttributes from block editor store - Remove hardcoded list of supported blocks - Keep new field type constants for UI controls - Update tests to mock the block editor store - Update documentation to reflect automatic detection Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
... Updated to use |
|
@copilot |
Refactored BlockBindingControls to dynamically generate UI controls based on WordPress's supported bindings list instead of using hardcoded switch statements. This allows it to work with any block that WordPress designates as supporting bindings. - Query __experimentalBlockBindingsSupportedAttributes to get bindable attributes for each block - Dynamically generate controls for each supported attribute - Map attribute names to appropriate field types with sensible defaults - Auto-generate human-readable labels for attributes - Add fallback support for custom blocks like remote-data-blocks/remote-html - Remove hardcoded switch statement with specific block cases Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
Refactored to handle generic block/attribute combinations. The component now queries WordPress's supported bindings for each block and dynamically generates controls instead of using hardcoded cases. Works with any block WordPress designates as bindable. Changes in commit 02211c7. |
- Use useSelect hook to memoize editor settings and prevent unnecessary re-renders - Use useMemo to cache supported attributes computation - Remove unnecessary div wrapper around controls - Apply key prop directly to components instead of wrapper Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
- Add key prop to Fragment wrapper in map for proper React reconciliation - Change @ts-ignore to @ts-expect-error for experimental API suppression Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
Co-authored-by: maxschmeling <112691+maxschmeling@users.noreply.github.com>
WordPress 6.7+ supports block bindings on additional blocks and attributes beyond the original four. This PR extends Remote Data Blocks to automatically support all blocks that WordPress core designates as bindable by querying the editor settings directly.
Changes
Dynamic Block Detection:
__experimentalBlockBindingsSupportedAttributesfrom WordPress's block editor settings in both the filter and UI componentsGeneric UI Controls:
BlockBindingControlsto dynamically generate UI controls for any block/attribute combinationuseSelectanduseMemoReact hooks for better performanceNew attributes supported:
core/button- added UI controls forlinkTarget,rel(in addition to existingurl,text)core/image- added UI control fortitle(in addition to existingurl,alt)Extensibility:
Custom blocks automatically work when registered with WordPress core's binding mechanisms:
Implementation:
addUsesContext()filter to determine supported blocksBlockBindingControlsto query supported attributes and generate controls dynamicallyremote-data-blocks/remote-htmlThis approach ensures the plugin automatically stays compatible with current and future WordPress versions without manual updates.
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.