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. Built from https://develop.svn.wordpress.org/trunk@55146 git-svn-id: http://core.svn.wordpress.org/trunk@54679 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
89706afd21
commit
cbb418fbe2
|
@ -216,13 +216,6 @@ function get_default_block_editor_settings() {
|
||||||
'allowedMimeTypes' => get_allowed_mime_types(),
|
'allowedMimeTypes' => get_allowed_mime_types(),
|
||||||
'defaultEditorStyles' => $default_editor_styles,
|
'defaultEditorStyles' => $default_editor_styles,
|
||||||
'blockCategories' => get_default_block_categories(),
|
'blockCategories' => get_default_block_categories(),
|
||||||
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
|
|
||||||
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
|
|
||||||
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
|
|
||||||
'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ),
|
|
||||||
'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
|
|
||||||
'enableCustomSpacing' => get_theme_support( 'custom-spacing' ),
|
|
||||||
'enableCustomUnits' => get_theme_support( 'custom-units' ),
|
|
||||||
'isRTL' => is_rtl(),
|
'isRTL' => is_rtl(),
|
||||||
'imageDefaultSize' => $image_default_size,
|
'imageDefaultSize' => $image_default_size,
|
||||||
'imageDimensions' => $image_dimensions,
|
'imageDimensions' => $image_dimensions,
|
||||||
|
@ -233,20 +226,9 @@ function get_default_block_editor_settings() {
|
||||||
'__unstableGalleryWithImageBlocks' => true,
|
'__unstableGalleryWithImageBlocks' => true,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Theme settings.
|
$theme_settings = get_classic_theme_supports_block_editor_settings();
|
||||||
$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
|
foreach ( $theme_settings as $key => $value ) {
|
||||||
if ( false !== $color_palette ) {
|
$editor_settings[ $key ] = $value;
|
||||||
$editor_settings['colors'] = $color_palette;
|
|
||||||
}
|
|
||||||
|
|
||||||
$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
|
|
||||||
if ( false !== $font_sizes ) {
|
|
||||||
$editor_settings['fontSizes'] = $font_sizes;
|
|
||||||
}
|
|
||||||
|
|
||||||
$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
|
|
||||||
if ( false !== $gradient_presets ) {
|
|
||||||
$editor_settings['gradients'] = $gradient_presets;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $editor_settings;
|
return $editor_settings;
|
||||||
|
@ -694,3 +676,40 @@ function get_block_editor_theme_styles() {
|
||||||
|
|
||||||
return $styles;
|
return $styles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the classic theme supports settings for block editor.
|
||||||
|
*
|
||||||
|
* @since 6.2.0
|
||||||
|
*
|
||||||
|
* @return array The classic theme supports settings.
|
||||||
|
*/
|
||||||
|
function get_classic_theme_supports_block_editor_settings() {
|
||||||
|
$theme_settings = array(
|
||||||
|
'disableCustomColors' => get_theme_support( 'disable-custom-colors' ),
|
||||||
|
'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
|
||||||
|
'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
|
||||||
|
'disableLayoutStyles' => get_theme_support( 'disable-layout-styles' ),
|
||||||
|
'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
|
||||||
|
'enableCustomSpacing' => get_theme_support( 'custom-spacing' ),
|
||||||
|
'enableCustomUnits' => get_theme_support( 'custom-units' ),
|
||||||
|
);
|
||||||
|
|
||||||
|
// Theme settings.
|
||||||
|
$color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
|
||||||
|
if ( false !== $color_palette ) {
|
||||||
|
$theme_settings['colors'] = $color_palette;
|
||||||
|
}
|
||||||
|
|
||||||
|
$font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
|
||||||
|
if ( false !== $font_sizes ) {
|
||||||
|
$theme_settings['fontSizes'] = $font_sizes;
|
||||||
|
}
|
||||||
|
|
||||||
|
$gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
|
||||||
|
if ( false !== $gradient_presets ) {
|
||||||
|
$theme_settings['gradients'] = $gradient_presets;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $theme_settings;
|
||||||
|
}
|
||||||
|
|
|
@ -286,7 +286,7 @@ class WP_Theme_JSON_Resolver {
|
||||||
* So we take theme supports, transform it to theme.json shape
|
* So we take theme supports, transform it to theme.json shape
|
||||||
* and merge the static::$theme upon that.
|
* and merge the static::$theme upon that.
|
||||||
*/
|
*/
|
||||||
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_default_block_editor_settings() );
|
$theme_support_data = WP_Theme_JSON::get_from_editor_settings( get_classic_theme_supports_block_editor_settings() );
|
||||||
if ( ! wp_theme_has_theme_json() ) {
|
if ( ! wp_theme_has_theme_json() ) {
|
||||||
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
|
if ( ! isset( $theme_support_data['settings']['color'] ) ) {
|
||||||
$theme_support_data['settings']['color'] = array();
|
$theme_support_data['settings']['color'] = array();
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-alpha-55145';
|
$wp_version = '6.2-alpha-55146';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue