Skip to content

Commit

Permalink
Template revisions API: move from experimental to compat/6.4 (#58920)
Browse files Browse the repository at this point in the history
* Initial commit:

Reverting #51774 by moving the experimental code into compat/6.4

The changes to the templates controller were made in WordPress 6.4. See: WordPress/wordpress-develop@1f51e1f

* Linty
  • Loading branch information
ramonjd authored Feb 12, 2024
1 parent a5c6aed commit cf18b3b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit cf18b3b

Please sign in to comment.