WordPress/wp-includes/rest-api/endpoints
Bernhard Reiter 8648d06284 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.

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


git-svn-id: http://core.svn.wordpress.org/trunk@57291 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-03-07 14:12:11 +00:00
..
class-wp-rest-application-passwords-controller.php
class-wp-rest-attachments-controller.php REST API: Add featured_media field to attachments endpoint. 2024-02-12 22:17:11 +00:00
class-wp-rest-autosaves-controller.php REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers. 2023-10-10 14:05:21 +00:00
class-wp-rest-block-directory-controller.php
class-wp-rest-block-pattern-categories-controller.php REST API: Cache schema in block pattern and menu item endpoints. 2023-06-28 15:53:26 +00:00
class-wp-rest-block-patterns-controller.php REST API: Cache schema in block pattern and menu item endpoints. 2023-06-28 15:53:26 +00:00
class-wp-rest-block-renderer-controller.php
class-wp-rest-block-types-controller.php Coding standards: Apply some changes after composer format. 2024-03-05 06:55:08 +00:00
class-wp-rest-blocks-controller.php Coding Standards: Remove extra space in a comment in WP_REST_Blocks_Controller. 2023-10-31 14:23:21 +00:00
class-wp-rest-comments-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00
class-wp-rest-edit-site-export-controller.php
class-wp-rest-font-collections-controller.php Editor: Ensure font collection metadata can be properly localized. 2024-02-21 19:27:14 +00:00
class-wp-rest-font-faces-controller.php Editor: Prevent infinite loops when filtering the font library folder. 2024-02-29 10:17:07 +00:00
class-wp-rest-font-families-controller.php REST API: Introduce the necessary endpoints for the font library. 2024-02-07 09:20:08 +00:00
class-wp-rest-global-styles-controller.php REST API: Revert the refactor of global styles endpoints in REST API in [57624]. 2024-02-13 15:13:17 +00:00
class-wp-rest-global-styles-revisions-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-menu-items-controller.php REST API: Correct the docblocks for various permission related methods. 2023-08-18 17:46:18 +00:00
class-wp-rest-menu-locations-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-menus-controller.php REST API: Correct the docblocks for various permission related methods. 2023-08-18 17:46:18 +00:00
class-wp-rest-navigation-fallback-controller.php General: Remove discouraged @return void annotations. 2023-10-16 15:17:23 +00:00
class-wp-rest-pattern-directory-controller.php Coding Standards: Remove redundant ignore annotations, take 5. 2023-10-02 11:27:24 +00:00
class-wp-rest-plugins-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00
class-wp-rest-post-statuses-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-post-types-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-posts-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-revisions-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-search-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-settings-controller.php Coding Standards: Remove superfluous blank lines at the end of various functions. 2023-09-08 10:03:21 +00:00
class-wp-rest-sidebars-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-site-health-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00
class-wp-rest-taxonomies-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-template-autosaves-controller.php REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers. 2023-10-10 14:05:21 +00:00
class-wp-rest-template-revisions-controller.php REST API: Fix issue with Template and Template Part Revision/Autosave REST API controllers. 2023-10-10 14:05:21 +00:00
class-wp-rest-templates-controller.php Block Hooks: Use new Templates Controller filter instead of action. 2024-03-07 14:12:11 +00:00
class-wp-rest-terms-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-themes-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-url-details-controller.php Bootstrap/Load: Introduce functions to check whether WordPress is serving a REST API request. 2024-01-19 17:40:09 +00:00
class-wp-rest-users-controller.php General: Consistently cast return value to int in functions that use ceil(). 2024-02-17 15:24:08 +00:00
class-wp-rest-widget-types-controller.php Coding Standards: Restore more descriptive variable names in a few class methods. 2023-09-14 12:46:20 +00:00
class-wp-rest-widgets-controller.php Coding Standards: Include one space after function keyword for closures. 2023-09-12 15:23:18 +00:00