Skip to content
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: Refactor the way sources are handled #6016

Closed

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Feb 2, 2024

Trac ticket: https://core.trac.wordpress.org/ticket/60282

Follow-up for #5888.

It fixes the coding style issues reported. It goes further and improves the code quality it other places where the logic for block bindings was added.

There are no functional changes.


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

Copy link

github-actions bot commented Feb 2, 2024

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 props-bot label.

Core SVN

If you're a Core Committer, use this list when committing to wordpress-develop in SVN:

Props: gziolo, mukesh27, youknowriad, santosguillamot.

GitHub Merge commits

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: gziolo <[email protected]>
Co-authored-by: mukeshpanchal27 <[email protected]>
Co-authored-by: youknowriad <[email protected]>
Co-authored-by: SantosGuillamot <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

Copy link

github-actions bot commented Feb 2, 2024

Test using WordPress Playground

The changes in this pull request can previewed and tested using a WordPress Playground instance.

WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser.

Some things to be aware of

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@youknowriad
Copy link
Contributor

Thanks for handing the follow-up @gziolo I appreciate it. On a quick glance, everything looks good to me.

* @param string $attribute_name The name of the target attribute.
* @return mixed The value computed for the source.
*/
function _block_bindings_pattern_overrides_get_value( array $source_args, $block_instance, string $attribute_name ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of private function is in general better as inline functions/closures. I think these are not authorized in Core yet right? Do you know more about the reasoning...

Copy link
Member Author

@gziolo gziolo Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about it, too. I’ll ask around and check the codebase. The only benefit of using another regular function like at the moment is the PHPDoc included.

Copy link
Member Author

@gziolo gziolo Feb 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You definitely can find places where inline functions are defined as params passed. You shouldn't use them when passing the callback to WP hooks, but here, it would make perfect sense. I'll confirm that and refactor the code, if possible, after adding more unit tests.

Copy link

@SantosGuillamot SantosGuillamot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good to me and the refactor makes sense 🙂

@gziolo gziolo force-pushed the update/block-bindings-refactoring branch from 668fe1b to b337f01 Compare February 2, 2024 19:53
@gziolo
Copy link
Member Author

gziolo commented Feb 2, 2024

Committed with https://core.trac.wordpress.org/changeset/57526.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants