-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Add a filter for the reusable block id #8912
Add a filter for the reusable block id #8912
Conversation
I noticed that this proposal doesn’t contain any documentation - both inline and general guidelines in the handbook how to use this hook. |
Cool suggestion—I think it makes sense. I'm wondering though if we should make this more general-purpose by passing the filter the
Yes, we'll need to document this. |
@noisysocks I've added inline documentation for the filter. I couldn't find where Gutenberg hooks are documented in the handbook. |
@gziolo We're waiting for this to improve compatibility with Gutenberg. Can this be included? |
Sorry, I missed that! Yes, we can include it. Actually it might be very useful. Let’s add some docs with ESNext/ES5 examples about the filter in this document: I also agree with the suggestion from @noisysocks that it would be neat to include the html as a param in the filter for some more advanced use cases. |
PHP in the |
fd0d80f
to
1cae5a9
Compare
Hi there. Is there any change this PR will get merged and included in WP 5.0? |
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'm fine with this going in, let's just change the filter name, as it'll be going straight into Core.
* | ||
* @param int $block_id The id of the reusable block | ||
*/ | ||
$reusable_block_id = apply_filters( 'gutenberg_reusable_block_id', $attributes['ref'] ); |
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.
Let's call the filter reusable_block_id
, we don't need to use the gutenberg_
prefix anymore.
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
It'd be useful if this filter also had the post ID that the reusable block is being embedding in. |
Done. I wasn't sure if I should have used |
It looks like a more general solution proposed in #11730 could work here, too. The only change that would need to be applied is that the other proposed filter would have to take |
Closing in favor of https://core.trac.wordpress.org/ticket/45451. Thank you for opening this PR. It looks like there is ongoing discussion about enabling such capability in WordPress core. |
Patch has landed in It should be released next month in WordPress 5.1. |
Description
Add a filter so that plugins and themes can filter the reusable block id and return a different block.
Why is this needed.
Plugins may want to display a different reusable block in some situations. Eg. WPML allows you to translate the reusable block. When rendering the page that contains the reusable block WPML can detect the current language and select the appropriate reusable block to display.
How has this been tested?
This has been tested with WPML using the follow code example.
Types of changes
Add a new filter
Checklist: