Skip to content

Commit

Permalink
Reverting post type registration changes as it assigns an autosave co…
Browse files Browse the repository at this point in the history
…ntroller. we
  • Loading branch information
ramonjd committed Nov 23, 2023
1 parent 66c3bcf commit dc628c5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 39 deletions.
26 changes: 11 additions & 15 deletions src/wp-includes/post.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,19 +473,15 @@ function create_initial_post_types() {
register_post_type(
'wp_global_styles',
array(
'label' => _x( 'Global Styles', 'post type general name' ),
'description' => __( 'Global styles to include in themes.' ),
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
'show_ui' => false,
'show_in_rest' => true,
'rewrite' => false,
'rest_base' => 'global-styles',
'rest_controller_class' => 'WP_REST_Global_Styles_Controller',
'revisions_rest_controller_class' => 'WP_REST_Global_Styles_Revisions_Controller',
'late_route_registration' => true,
'capabilities' => array(
'label' => _x( 'Global Styles', 'post type general name' ),
'description' => __( 'Global styles to include in themes.' ),
'public' => false,
'_builtin' => true, /* internal use only. don't use this when registering your own post type. */
'_edit_link' => '/site-editor.php?canvas=edit', /* internal use only. don't use this when registering your own post type. */
'show_ui' => false,
'show_in_rest' => false,
'rewrite' => false,
'capabilities' => array(
'read' => 'edit_theme_options',
'create_posts' => 'edit_theme_options',
'edit_posts' => 'edit_theme_options',
Expand All @@ -494,8 +490,8 @@ function create_initial_post_types() {
'edit_others_posts' => 'edit_theme_options',
'delete_others_posts' => 'edit_theme_options',
),
'map_meta_cap' => true,
'supports' => array(
'map_meta_cap' => true,
'supports' => array(
'title',
'editor',
'revisions',
Expand Down
4 changes: 4 additions & 0 deletions src/wp-includes/rest-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@ function create_initial_rest_routes() {
$controller = new WP_REST_Block_Types_Controller();
$controller->register_routes();

// Global Styles revisions.
$controller = new WP_REST_Global_Styles_Revisions_Controller();
$controller->register_routes();

// Global Styles.
$controller = new WP_REST_Global_Styles_Controller();
$controller->register_routes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
* @see WP_REST_Controller
*/
class WP_REST_Global_Styles_Revisions_Controller extends WP_REST_Revisions_Controller {
/**
* Parent post type.
*
* @since 6.3.0
* @var string
*/
private $parent_post_type;

/**
* Parent controller.
*
Expand All @@ -43,23 +35,13 @@ class WP_REST_Global_Styles_Revisions_Controller extends WP_REST_Revisions_Contr
* Constructor.
*
* @since 6.3.0
*
* @param string $parent_post_type Post type of the parent.
*/
public function __construct( $parent_post_type ) {
parent::__construct( $parent_post_type );
$this->parent_post_type = $parent_post_type;
$post_type_object = get_post_type_object( $parent_post_type );
$parent_controller = $post_type_object->get_rest_controller();

if ( ! $parent_controller ) {
$parent_controller = new WP_REST_Global_Styles_Controller();
}

$this->parent_controller = $parent_controller;
public function __construct() {
parent::__construct( 'wp_global_styles' );
$this->parent_controller = new WP_REST_Global_Styles_Controller();
$this->rest_base = 'revisions';
$this->parent_base = ! empty( $post_type_object->rest_base ) ? $post_type_object->rest_base : $post_type_object->name;
$this->namespace = ! empty( $post_type_object->rest_namespace ) ? $post_type_object->rest_namespace : 'wp/v2';
$this->parent_base = $this->parent_controller->rest_base;
$this->namespace = $this->parent_controller->namespace;
}

/**
Expand Down Expand Up @@ -322,6 +304,8 @@ public function get_item_schema() {
unset( $schema['properties']['guid'] );
unset( $schema['properties']['slug'] );
unset( $schema['properties']['meta'] );
unset( $schema['properties']['content'] );
unset( $schema['properties']['excerpt'] );

$this->schema = $schema;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function test_get_item_schema() {
$data = $response->get_data();
$properties = $data['schema']['properties'];

$this->assertCount( 10, $properties, 'Schema properties array has exactly 9 elements.' );
$this->assertCount( 10, $properties, 'Schema properties array has exactly 10 elements.' );
$this->assertArrayHasKey( 'id', $properties, 'Schema properties array has "id" key.' );
$this->assertArrayHasKey( 'styles', $properties, 'Schema properties array has "styles" key.' );
$this->assertArrayHasKey( 'title', $properties, 'Schema properties array has "title" key.' );
Expand Down

0 comments on commit dc628c5

Please sign in to comment.