Skip to content

Commit

Permalink
Font Families and Faces: disable autosaves using empty class (#58018)
Browse files Browse the repository at this point in the history
  • Loading branch information
creativecoder committed Jan 22, 2024
1 parent 51345f0 commit d45d540
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 28 deletions.

This file was deleted.

6 changes: 4 additions & 2 deletions lib/experimental/fonts/font-library/font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ function gutenberg_init_font_library_routes() {
'show_in_rest' => true,
'rest_base' => 'font-families',
'rest_controller_class' => 'WP_REST_Font_Families_Controller',
'autosave_rest_controller_class' => 'WP_REST_Autosave_Fonts_Controller',
// Disable autosave endpoints for font families.
'autosave_rest_controller_class' => 'stdClass',
);
register_post_type( 'wp_font_family', $args );

Expand Down Expand Up @@ -83,7 +84,8 @@ function gutenberg_init_font_library_routes() {
'show_in_rest' => true,
'rest_base' => 'font-families/(?P<font_family_id>[\d]+)/font-faces',
'rest_controller_class' => 'WP_REST_Font_Faces_Controller',
'autosave_rest_controller_class' => 'WP_REST_Autosave_Fonts_Controller',
// Disable autosave endpoints for font faces.
'autosave_rest_controller_class' => 'stdClass',
)
);

Expand Down
1 change: 0 additions & 1 deletion lib/load.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ function gutenberg_is_experiment_enabled( $name ) {
require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-families-controller.php';
require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-faces-controller.php';
require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php';
require __DIR__ . '/experimental/fonts/font-library/class-wp-rest-autosave-fonts-controller.php';
require __DIR__ . '/experimental/fonts/font-library/font-library.php';
}

Expand Down
16 changes: 16 additions & 0 deletions phpunit/tests/fonts/font-library/wpRestFontFacesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,22 @@ public function test_register_routes() {
);
}

public function test_font_faces_no_autosave_routes() {
// @core-merge: Enable this test.
$this->markTestSkipped( 'This test only works with WP 6.4 and above. Enable it once 6.5 is released.' );
$routes = rest_get_server()->get_routes();
$this->assertArrayNotHasKey(
'/wp/v2/font-families/(?P<font_family_id>[\d]+)/font-faces/(?P<id>[\d]+)/autosaves',
$routes,
'Font faces autosaves route exists.'
);
$this->assertArrayNotHasKey(
'/wp/v2/font-families/(?P<font_family_id>[\d]+)/font-faces/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)',
$routes,
'Font faces autosaves by id route exists.'
);
}

/**
* @covers WP_REST_Font_Faces_Controller::get_context_param
*/
Expand Down
16 changes: 16 additions & 0 deletions phpunit/tests/fonts/font-library/wpRestFontFamiliesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,22 @@ public function test_register_routes() {
);
}

public function test_font_families_no_autosave_routes() {
// @core-merge: Enable this test.
$this->markTestSkipped( 'This test only works with WP 6.4 and above. Enable it once 6.5 is released.' );
$routes = rest_get_server()->get_routes();
$this->assertArrayNotHasKey(
'/wp/v2/font-families/(?P<id>[\d]+)/autosaves',
$routes,
'Font families autosaves route exists.'
);
$this->assertArrayNotHasKey(
'/wp/v2/font-families/(?P<parent>[\d]+)/autosaves/(?P<id>[\d]+)',
$routes,
'Font families autosaves by id route exists.'
);
}

/**
* @covers WP_REST_Font_Families_Controller::get_context_param
*/
Expand Down

0 comments on commit d45d540

Please sign in to comment.