-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 Hooks API: Add Templates Controller filter to avoid triggering wp_update_post #6225
Block Hooks API: Add Templates Controller filter to avoid triggering wp_update_post #6225
Conversation
Test using WordPress PlaygroundThe 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
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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 Committers: Use this line as a base for the props when committing in SVN:
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
376ebdf
to
0e65613
Compare
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
This should be ready for review 😊 |
That makes sense to me. Avoiding two database operations should be one of the goals of this fix. See my #6225 (comment), where I'm unsure if it will work as intended for the logic that injects blocks. |
src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
Outdated
Show resolved
Hide resolved
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.
Is there test coverage? Can we add tests.
…troller.php Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
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 tested the PR against the original issue and it works just fine! Thanks @tjcafferkey for picking it up 🚀
I'll add some 👍 |
fb29d99
to
9bd9fcb
Compare
@swissspidy I've added some tests, both for the filter in isolation, and when used inside the controller. LMK if this looks good to you, or if you'd like anything else covered 🙂 |
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.
Looks good to me 👍🏻
Committed to Core in https://core.trac.wordpress.org/changeset/57790. |
Backported to the |
Bootstrap block bindings sources earlier in the process through an inline script to ensure they are available when developers want to extend them in the client. Following the same pattern other APIs like registering block types are doing. Props santosguillamot, cbravobernal, gziolo. Fixes #6225. git-svn-id: https://develop.svn.wordpress.org/trunk@59238 602fd350-edb4-49c9-b593-d223f7449a82
This change is inspired by this PR WordPress/gutenberg#59561 since they are suffering from the same problem.
By creating a rest_pre_insert_{$this->post_type} filter in the
WP_REST_Templates_Controller
rather than using therest_insert_{$this->post_type}
action. This avoids callingwp_update_post
twice, which was the original reason for the issue, as it removed the backslash from the already-encoded entity. I suspectwp_update_post
was also creating additional revisions which was mentioned in the linked Trac ticket.By creating this filter it also creates consistency with the
WP_REST_Posts_Controller
which has the same filter.Trac ticket: https://core.trac.wordpress.org/ticket/60671
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.