-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Block Bindings: Backport block bindings refactor from WordPress core #58683
Block Bindings: Backport block bindings refactor from WordPress core #58683
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core SVNIf you're a Core Committer, use this list when committing to
GitHub Merge commitsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ lib/compat/wordpress-6.5/block-bindings/block-bindings.php ❔ lib/compat/wordpress-6.5/block-bindings/class-wp-block-bindings-registry.php ❔ lib/compat/wordpress-6.5/blocks.php ❔ lib/load.php ❔ lib/compat/wordpress-6.5/block-bindings/pattern-overrides.php ❔ lib/compat/wordpress-6.5/block-bindings/post-meta.php |
* @param string $source_name The name of the source. It must be a string containing a namespace prefix, i.e. | ||
* `my-plugin/my-custom-source`. It must only contain lowercase alphanumeric | ||
* characters, the forward slash `/` and dashes. | ||
* @param array $source_properties { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also add this on the WP_Block_Bindings_Registry::register()
method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in this commit: link.
if ( ! isset( $block['attrs']['metadata']['bindings'] ) || ! isset( $allowed_blocks[ $block_instance->name ] ) ) { | ||
if ( | ||
! isset( $allowed_blocks[ $block_instance->name ] ) || | ||
empty( $parsed_block['attrs']['metadata']['bindings'] ) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here
we added a check with isset()
but I think empty()
is even more appropriate
(like you did). Let's remember to update it in Core
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some minor comments (non-blocking).
Looks good to me overall! 👍
I also took the opportunity to not escape the attribute passed to |
What?
In this pull request, I'm moving the changes made in this PR from WordPress core.
Why?
To keep both codebases in sync and implement the improvements made there.
How?
Mostly copying and pasting and adapting the few things needed by Gutenberg.
Testing Instructions
Ensure that the existing bindings keep working as expected:
In a page
Test paragraph
Test heading
Repeat the paragraph test but using a heading.
Test button
Test image
In a template
Go to a page template, for example, and repeat the process. In this case, the blocks can't show the value of the custom fields because it depends on each page. They should show a placeholder instead.
Test pattern syncing overrides