From cf18b3bd947be8b250cd2c18b0c496d6dbe85930 Mon Sep 17 00:00:00 2001 From: Ramon Date: Tue, 13 Feb 2024 04:15:06 +1100 Subject: [PATCH] Template revisions API: move from experimental to compat/6.4 (#58920) * Initial commit: Reverting https://github.com/WordPress/gutenberg/pull/51774 by moving the experimental code into compat/6.4 The changes to the templates controller were made in WordPress 6.4. See: https://github.com/WordPress/wordpress-develop/commit/1f51e1f4f6c81238fffed706ff165795ea34d522 * Linty --- ...tenberg-rest-templates-controller-6-4.php} | 6 ++--- lib/compat/wordpress-6.4/rest-api.php | 20 +++++++++++++++++ lib/experimental/rest-api.php | 22 ------------------- lib/load.php | 2 +- 4 files changed, 24 insertions(+), 26 deletions(-) rename lib/{experimental/class-gutenberg-rest-template-revision-count.php => compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php} (91%) diff --git a/lib/experimental/class-gutenberg-rest-template-revision-count.php b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php similarity index 91% rename from lib/experimental/class-gutenberg-rest-template-revision-count.php rename to lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php index 17fb34e05ecfe..ec969519f9ac4 100644 --- a/lib/experimental/class-gutenberg-rest-template-revision-count.php +++ b/lib/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php @@ -1,19 +1,19 @@ register_routes(); } add_action( 'rest_api_init', 'gutenberg_register_rest_block_patterns_routes' ); + + +if ( ! function_exists( 'wp_api_template_revision_args' ) ) { + /** + * Hook in to the template and template part post types and decorate + * the rest endpoint with the revision count. + * + * @param array $args Current registered post type args. + * @param string $post_type Name of post type. + * + * @return array + */ + function wp_api_template_revision_args( $args, $post_type ) { + if ( 'wp_template' === $post_type || 'wp_template_part' === $post_type ) { + $args['rest_controller_class'] = 'Gutenberg_REST_Templates_Controller_6_4'; + } + return $args; + } +} +add_filter( 'register_post_type_args', 'wp_api_template_revision_args', 10, 2 ); diff --git a/lib/experimental/rest-api.php b/lib/experimental/rest-api.php index 7c6a9bf74d739..77f7d091d2655 100644 --- a/lib/experimental/rest-api.php +++ b/lib/experimental/rest-api.php @@ -101,25 +101,3 @@ function gutenberg_auto_draft_get_sample_permalink( $permalink, $id, $title, $na return $permalink; } add_filter( 'get_sample_permalink', 'gutenberg_auto_draft_get_sample_permalink', 10, 5 ); - -if ( ! function_exists( 'wp_api_template_revision_args' ) ) { - /** - * Hook in to the template and template part post types and decorate - * the rest endpoint with the revision count. - * - * When merging to core, this can be removed once Gutenberg_REST_Template_Revision_Count is - * merged with WP_REST_Template_Controller. - * - * @param array $args Current registered post type args. - * @param string $post_type Name of post type. - * - * @return array - */ - function wp_api_template_revision_args( $args, $post_type ) { - if ( 'wp_template' === $post_type || 'wp_template_part' === $post_type ) { - $args['rest_controller_class'] = 'Gutenberg_REST_Template_Revision_Count'; - } - return $args; - } -} -add_filter( 'register_post_type_args', 'wp_api_template_revision_args', 10, 2 ); diff --git a/lib/load.php b/lib/load.php index 47d41fb50b3b5..b111c8e0d7921 100644 --- a/lib/load.php +++ b/lib/load.php @@ -36,6 +36,7 @@ function gutenberg_is_experiment_enabled( $name ) { } // WordPress 6.4 compat. + require_once __DIR__ . '/compat/wordpress-6.4/class-gutenberg-rest-templates-controller-6-4.php'; require_once __DIR__ . '/compat/wordpress-6.4/class-gutenberg-rest-global-styles-revisions-controller-6-4.php'; require_once __DIR__ . '/compat/wordpress-6.4/class-gutenberg-rest-block-patterns-controller.php'; require_once __DIR__ . '/compat/wordpress-6.4/rest-api.php'; @@ -53,7 +54,6 @@ function gutenberg_is_experiment_enabled( $name ) { if ( ! class_exists( 'WP_Rest_Customizer_Nonces' ) ) { require_once __DIR__ . '/experimental/class-wp-rest-customizer-nonces.php'; } - require_once __DIR__ . '/experimental/class-gutenberg-rest-template-revision-count.php'; require_once __DIR__ . '/experimental/rest-api.php'; require_once __DIR__ . '/experimental/kses-allowed-html.php';