Make WordPress Core


Ignore:
Timestamp:
01/26/2023 06:37:47 PM (4 years ago)
Author:
flixos90
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r55086 r55146  
    217217                'defaultEditorStyles'              => $default_editor_styles,
    218218                'blockCategories'                  => get_default_block_categories(),
    219                 'disableCustomColors'              => get_theme_support( 'disable-custom-colors' ),
    220                 'disableCustomFontSizes'           => get_theme_support( 'disable-custom-font-sizes' ),
    221                 'disableCustomGradients'           => get_theme_support( 'disable-custom-gradients' ),
    222                 'disableLayoutStyles'              => get_theme_support( 'disable-layout-styles' ),
    223                 'enableCustomLineHeight'           => get_theme_support( 'custom-line-height' ),
    224                 'enableCustomSpacing'              => get_theme_support( 'custom-spacing' ),
    225                 'enableCustomUnits'                => get_theme_support( 'custom-units' ),
    226219                'isRTL'                            => is_rtl(),
    227220                'imageDefaultSize'                 => $image_default_size,
    … …  
    234227        );
    235228
    236         // Theme settings.
    237         $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
    238         if ( false !== $color_palette ) {
    239                 $editor_settings['colors'] = $color_palette;
    240         }
    241 
    242         $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
    243         if ( false !== $font_sizes ) {
    244                 $editor_settings['fontSizes'] = $font_sizes;
    245         }
    246 
    247         $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
    248         if ( false !== $gradient_presets ) {
    249                 $editor_settings['gradients'] = $gradient_presets;
     229        $theme_settings = get_classic_theme_supports_block_editor_settings();
     230        foreach ( $theme_settings as $key => $value ) {
     231                $editor_settings[ $key ] = $value;
    250232        }
    251233
    … …  
    695677        return $styles;
    696678}
     679
     680/**
     681 * Returns the classic theme supports settings for block editor.
     682 *
     683 * @since 6.2.0
     684 *
     685 * @return array The classic theme supports settings.
     686 */
     687function get_classic_theme_supports_block_editor_settings() {
     688        $theme_settings = array(
     689                'disableCustomColors'    => get_theme_support( 'disable-custom-colors' ),
     690                'disableCustomFontSizes' => get_theme_support( 'disable-custom-font-sizes' ),
     691                'disableCustomGradients' => get_theme_support( 'disable-custom-gradients' ),
     692                'disableLayoutStyles'    => get_theme_support( 'disable-layout-styles' ),
     693                'enableCustomLineHeight' => get_theme_support( 'custom-line-height' ),
     694                'enableCustomSpacing'    => get_theme_support( 'custom-spacing' ),
     695                'enableCustomUnits'      => get_theme_support( 'custom-units' ),
     696        );
     697
     698        // Theme settings.
     699        $color_palette = current( (array) get_theme_support( 'editor-color-palette' ) );
     700        if ( false !== $color_palette ) {
     701                $theme_settings['colors'] = $color_palette;
     702        }
     703
     704        $font_sizes = current( (array) get_theme_support( 'editor-font-sizes' ) );
     705        if ( false !== $font_sizes ) {
     706                $theme_settings['fontSizes'] = $font_sizes;
     707        }
     708
     709        $gradient_presets = current( (array) get_theme_support( 'editor-gradient-presets' ) );
     710        if ( false !== $gradient_presets ) {
     711                $theme_settings['gradients'] = $gradient_presets;
     712        }
     713
     714        return $theme_settings;
     715}
Note: See TracChangeset for help on using the changeset viewer.