From 8cb55f545199e2d0de114992ecfd991257a3e082 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Fri, 23 Sep 2022 14:00:09 +0000 Subject: [PATCH] Block Editor: Remove repetitive calls to `file_get_contents()` in block editor settings. The `get_default_block_editor_settings()` function used to repeatedly get the `default-editor-styles.css` file contents without any implementation to avoid this. This commit utilizes a static variable to remove repetitive calls made during the same request. In tests ran on the front page of a site using Xdebug & Webgrind, the total `file_get_contents()` invocation count goes down from 181 to 93, and total self cost (the time that the function is responsible for) goes down from 160 ms to 93 ms. Follow-up to [52042]. Props aristath, mukesh27. Fixes #56637. Built from https://develop.svn.wordpress.org/trunk@54291 git-svn-id: http://core.svn.wordpress.org/trunk@53850 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/block-editor.php | 13 +++++++++---- wp-includes/version.php | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/wp-includes/block-editor.php b/wp-includes/block-editor.php index c177d9619d..1c67e6cc7a 100644 --- a/wp-includes/block-editor.php +++ b/wp-includes/block-editor.php @@ -192,12 +192,17 @@ function get_default_block_editor_settings() { // These styles are used if the "no theme styles" options is triggered or on // themes without their own editor styles. $default_editor_styles_file = ABSPATH . WPINC . '/css/dist/block-editor/default-editor-styles.css'; - if ( file_exists( $default_editor_styles_file ) ) { + + static $default_editor_styles_file_contents = false; + if ( ! $default_editor_styles_file_contents && file_exists( $default_editor_styles_file ) ) { + $default_editor_styles_file_contents = file_get_contents( $default_editor_styles_file ); + } + + $default_editor_styles = array(); + if ( $default_editor_styles_file_contents ) { $default_editor_styles = array( - array( 'css' => file_get_contents( $default_editor_styles_file ) ), + array( 'css' => $default_editor_styles_file_contents ), ); - } else { - $default_editor_styles = array(); } $editor_settings = array( diff --git a/wp-includes/version.php b/wp-includes/version.php index a7b696c36e..bd988c90e7 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.1-beta1-54290'; +$wp_version = '6.1-beta1-54291'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.