Bindings: Try to integrate SCF custom fields in the Attributes panel #169
+32
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related to #154.
This is a proof of concept that explores including registered custom SCF fields in the Attributes panel, which is currently limited to show only fields from the Post Meta binding source.
This change alone allows connecting in the editor fields registered with SCF with all core blocks that support Block Bindings.
Approach
This prototype uses the Proxy object to override the
getBlockBindingsSources
method inwp.blocks
global. Proxy is necessary because properties insidewp.blocks
are set as readonly, so that is an elegant way to tap into the existing system.I tried replicating the same Attributes panel by duplicating code from Gutenberg, but it uses some internal/private APIs that are difficult to mirror in a plugin. Therefore, I opted for an existing method that is used to construct the list of fields that can be connected with blocks. In the ideal world, some changes in Gutenberg would need to be applied to allow custom Block Bindings sources to define the list of fields to connect.
I haven’t explored that yet, but in the editor, users see the
SCF Fields
label in readonly mode without more details about the specific connected fields. It's probably caused by the fact that SCF Fields source is only registered on the server, so it doesn’t have the logic necessary to show something more specific like Post Meta does.Demo
Screen.Recording.2025-05-23.at.14.51.20.mov