mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-08-12 21:00:21 +00:00
Themes: Avoid unnecessary database queries from get_default_block_editor_settings() in WP_Theme_JSON_Resolver::get_theme_data().
The `get_default_block_editor_settings()` function included several pieces of data that are irrelevant for the purpose that `WP_Theme_JSON_Resolver` was calling it for, yet resulted in three database queries on page load that can be avoided. This changeset introduces a new function `get_classic_theme_supports_block_editor_settings()` to takes responsibility of only the data needed in `WP_Theme_JSON_Resolver`, which now uses that function. This leads to a reduction of database queries and accordingly a performance improvement. Props mamaduka, spacedmonkey, oandregal, flixos90, audrasjb, mukesh27. Fixes #57547. git-svn-id: https://develop.svn.wordpress.org/trunk@55146 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -568,6 +568,44 @@ class Tests_Blocks_Editor extends WP_UnitTestCase {
|
||||
$this->assertStringContainsString( $expected, $haystack );
|
||||
}
|
||||
|
||||
/**
|
||||
* @ticket 57547
|
||||
*
|
||||
* @covers ::get_classic_theme_supports_block_editor_settings
|
||||
*/
|
||||
public function test_get_classic_theme_supports_block_editor_settings() {
|
||||
$font_sizes = array(
|
||||
array(
|
||||
'name' => 'Small',
|
||||
'size' => 12,
|
||||
'slug' => 'small',
|
||||
),
|
||||
array(
|
||||
'name' => 'Regular',
|
||||
'size' => 16,
|
||||
'slug' => 'regular',
|
||||
),
|
||||
);
|
||||
|
||||
add_theme_support( 'editor-font-sizes', $font_sizes );
|
||||
$settings = get_classic_theme_supports_block_editor_settings();
|
||||
remove_theme_support( 'editor-font-sizes' );
|
||||
|
||||
$this->assertFalse( $settings['disableCustomColors'], 'Value for array key "disableCustomColors" does not match expectations' );
|
||||
$this->assertFalse( $settings['disableCustomFontSizes'], 'Value for array key "disableCustomFontSizes" does not match expectations' );
|
||||
$this->assertFalse( $settings['disableCustomGradients'], 'Value for array key "disableCustomGradients" does not match expectations' );
|
||||
$this->assertFalse( $settings['disableLayoutStyles'], 'Value for array key "disableLayoutStyles" does not match expectations' );
|
||||
$this->assertFalse( $settings['enableCustomLineHeight'], 'Value for array key "enableCustomLineHeight" does not match expectations' );
|
||||
$this->assertFalse( $settings['enableCustomSpacing'], 'Value for array key "enableCustomSpacing" does not match expectations' );
|
||||
$this->assertFalse( $settings['enableCustomUnits'], 'Value for array key "enableCustomUnits" does not match expectations' );
|
||||
|
||||
$this->assertSame(
|
||||
$font_sizes,
|
||||
$settings['fontSizes'],
|
||||
'Value for array key "fontSizes" does not match expectations'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider.
|
||||
*
|
||||
|
||||
@@ -2645,7 +2645,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_get_editor_settings_custom_units_can_be_disabled() {
|
||||
add_theme_support( 'custom-units', array() );
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() );
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
|
||||
remove_theme_support( 'custom-units' );
|
||||
|
||||
$expected = array(
|
||||
@@ -2662,7 +2662,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_get_editor_settings_custom_units_can_be_enabled() {
|
||||
add_theme_support( 'custom-units' );
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() );
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
|
||||
remove_theme_support( 'custom-units' );
|
||||
|
||||
$expected = array(
|
||||
@@ -2679,7 +2679,7 @@ class Tests_Theme_wpThemeJson extends WP_UnitTestCase {
|
||||
*/
|
||||
public function test_get_editor_settings_custom_units_can_be_filtered() {
|
||||
add_theme_support( 'custom-units', 'rem', 'em' );
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() );
|
||||
$actual = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
|
||||
remove_theme_support( 'custom-units' );
|
||||
|
||||
$expected = array(
|
||||
|
||||
Reference in New Issue
Block a user