-
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
Filter to allow plugins override block attributes #11730
Filter to allow plugins override block attributes #11730
Conversation
lib/class-wp-block-type.php
Outdated
* @param array $prepared_attributes block attributes | ||
*/ | ||
|
||
$prepared_attributes = apply_filters( 'block_attributes', $prepared_attributes ); |
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.
IMO $this
should be passed to the filter as well. Otherwise one has no idea which block type the attributes are for.
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.
Can't it pass the block name instead of $this
? What other information plugins would need? It feels like there is no need to pass the block type object by reference.
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.
Actually, I second idea to pass the whole object. Mind it, plugin authors will filter not only core Blocks but also many 3rd party with who knows what kind of data. Sometimes it will be helpful to have bigger picture inside of the hook.
But finally it is up to you, I can change but please decide :)
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.
+1 It will be more useful to be given the whole object here instead of the "block type name".
I left some comments because the added code does not yet follow the WordPress PHP documentation standards. |
Thank you @swissspidy I adjusted the code according your suggestions |
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.
@pento, I didn't follow PHP based hooks for Gutenberg. Could you double check this one?
The use case described makes sense. What I'm not quite sure is how it relates to #8912 which also tries to integrate WPML plugin using reusable blocks:
We are preparing in WPML code to make it translatable, but we need to hook somewhere somewhere in Gutenberg to filter values. This place seems to be most appropriate for this.
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.
This needs to be fixed:
FILE: /app/lib/class-wp-block-type.php
FOUND 2 ERRORS AFFECTING 2 LINES
154 | ERROR | [x] Whitespace found at end of line
| | (Squiz.WhiteSpace.SuperfluousWhitespace.EndLine)
156 | ERROR | [x] Whitespace found at end of line
| | (Squiz.WhiteSpace.SuperfluousWhitespace.EndLine)PHPCBF CAN FIX THE 2 MARKED SNIFF VIOLATIONS AUTOMATICALLY
Can we also consolidate changes proposed in #8912 to avoid introducing another more targeted hook: I guess, we would have to pass a post id or even a full object. |
I think we should also propose the same change in Trac to ensure it lands in WordPress core before RC starts. |
about passing post id: I am not sure if I understood, but I think post is not available in this scope (it is in globals, this is what you meant? to take it from global? if so, it could be redundant: hooked filter will have access to global as well so no need to pass it) about Trac: I don't know how to propose it there, could you give me a hand? |
This does not seem ready to merge in 4.5, so moving to 4.6. |
@gziolo if this is postponed to 4.6, should I still add similar change to wordpress repository? if yes, could you guide me how to (especially where exactly)? |
5.0 RC is out so this won't be included for the initial 5.0 release. This is a feature request and it's now planned for the first following release |
Thanks @gziolo Do I need to to take any action or just wait for it? |
It is still not clear what the process is going to look like after 5.0 is out. It probably makes sense to open a ticket in Trac and propose the changes directly in WordPress Core. @swissspidy and @pento should know better how to proceed. |
@swissspidy / @pento could you advice how to copy this ticket to trac? |
@kkarpieszuk Sure! Since You can create a new ticket at https://core.trac.wordpress.org/newticket. If you don't have a WordPress.org account yet, you can sign up at https://login.wordpress.org/. As for the ticket, make sure the type is "enhancement" and the version is 5.0. Creating a patch is a little bit different than creating a PR here on GitHub. You can clone the Git repository from develop.git.wordpress.org. Make sure to check out the 5.0 branch. Then, apply the changes from this PR to Make sure to change the Also, I'd replace After that, create a patch using You can include the same description from this PR when creating the ticket. You can also link to this PR for full context. Let me know if you need any help during the whole process! I'll definitely keep an eye open on new tickets :-) |
Hi @swissspidy thank you for detailed instructions but I can't connect to git server. Is the url correct? What protocol should I use? this is what I tried:
|
@kkarpieszuk I think you need a trailing slash, e.g. |
@swissspidy for https I didn't make any difference, but for ssh:// there is some progress. Looks like I need to have access granted, but how?
I tried |
@kkarpieszuk Sorry you have all these troubles. I don't think specific access is needed. But in any case, there's a mirror at https://github.com/wordpress/wordpress-develop/ that one can use. This should work for sure :-) |
@swissspidy thank you, done (I hope)! :) Could you review if everything is done correctly? |
Closing in favor of https://core.trac.wordpress.org/ticket/45451. |
thanks a lot!! |
Description
Closes #8912, #11195 (related but more specific proposals).
Add a filter so plugins and themes can override block attributes.
Why is this needed?
Dynamic blocks, rendered server side keep their values in block attributes. Some of those attributes might be texts printed in the front-end to be read by people. This kind of strings should be available for translation.
We are preparing in WPML code to make it translatable, but we need to hook somewhere somewhere in Gutenberg to filter values. This place seems to be most appropriate for this.
How has this been tested?
This has been tested in WPML with following code example (to translate dynamic strings created with ACF Blocks beta).
Types of changes
Add a new filter
Checklist: