Skip to content
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

Template revisions API: move from experimental to compat/6.4 #58920

Merged
merged 2 commits into from Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,19 +1,19 @@
<?php
/**
* REST API: Gutenberg_REST_Template_Revision_Count class
* REST API: Gutenberg_REST_Templates_Controller_6_4 class
*
* @package gutenberg
*/

/**
* Gutenberg_REST_Template_Revision_Count class
* Gutenberg_REST_Templates_Controller_6_4 class
*
* Template revision changes are waiting on a core change to be merged.
* See: https://github.com/WordPress/gutenberg/pull/45215#issuecomment-1592704026
* When merging into core, prepare_revision_links() should be merged with
* WP_REST_Templates_Controller::prepare_links().
*/
class Gutenberg_REST_Template_Revision_Count extends WP_REST_Templates_Controller {
class Gutenberg_REST_Templates_Controller_6_4 extends WP_REST_Templates_Controller {
/**
* Add revisions to the response.
*
Expand Down
20 changes: 20 additions & 0 deletions lib/compat/wordpress-6.4/rest-api.php
Expand Up @@ -18,3 +18,23 @@ function gutenberg_register_rest_block_patterns_routes() {
$block_patterns->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 );
22 changes: 0 additions & 22 deletions lib/experimental/rest-api.php
Expand Up @@ -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 );
2 changes: 1 addition & 1 deletion lib/load.php
Expand Up @@ -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';
Expand All @@ -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';
Expand Down