WordPress/wp-includes/rest-api
Bernhard Reiter a113f3da53 Block Hooks: Use new Templates Controller filter instead of action.
This changeset adds a new `rest_pre_insert_{$this->post_type}` filter in the `WP_REST_Templates_Controller`, where it is applied to the return value of the `prepare_item_for_database` method. (This is consistent with the `WP_REST_Post_Controller`, where that filter has existed before.)

The new filter is then used to inject hooked blocks into the template (or template part) content received via the endpoint, prior to persisting it to the database.

This supersedes the previous mechanism, which was using the `rest_after_insert_{$this->post_type}` ''action'', from which it performed an additional `wp_update_post` call to update the template (part) content with the hooked blocks injected. The new technique eschews that additional call and the resulting extra revision it created, as well as a problem with regard to duplicated escaping and sanitization, which had caused some special characters to be garbled.

Reviewed by swissspidy.
Merges [57790] to the to the 6.5 branch.

Props tomjcafferkey, gziolo, swissspidy, karolmanijak.
Fixes #60671.
Built from https://develop.svn.wordpress.org/branches/6.5@57802


git-svn-id: http://core.svn.wordpress.org/branches/6.5@57303 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-03-11 14:15:33 +00:00
..
endpoints Block Hooks: Use new Templates Controller filter instead of action. 2024-03-11 14:15:33 +00:00
fields REST API: Improve error handling in REST meta fields 2024-02-13 09:57:08 +00:00
search REST API: Clarify documentation for methods and filters relating to REST API search endpoints. 2024-02-16 21:35:12 +00:00
class-wp-rest-request.php Docs: Replace multiple single line comments with multi-line comments. 2023-07-10 23:00:22 +00:00
class-wp-rest-response.php Coding Standards: Always use parentheses when instantiating an object. 2022-11-29 15:51:14 +00:00
class-wp-rest-server.php REST API: Pass correct context to embedded items. 2024-02-20 09:10:09 +00:00