Editor: Improve frontend performance for `get_default_block_editor_settings()`.
The `wp_max_upload_size()` function can be expensive to call, especially for large sites or multisites. For the frontend usage of `get_default_block_editor_settings()` knowing the allowed upload size is typically unnecessary. This changeset adds a condition so that `wp_max_upload_size()` is only called if the current user can actually `upload_files`. It keeps the data present when it is actually needed while avoiding the execution overhead when it is not needed. Props janthiel, Clorith, flixos90, spacedmonkey. Fixes #56815. Built from https://develop.svn.wordpress.org/trunk@54769 git-svn-id: http://core.svn.wordpress.org/trunk@54321 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
4c90be7e91
commit
5f61131cc6
|
@ -153,10 +153,15 @@ function get_allowed_block_types( $block_editor_context ) {
|
||||||
*/
|
*/
|
||||||
function get_default_block_editor_settings() {
|
function get_default_block_editor_settings() {
|
||||||
// Media settings.
|
// Media settings.
|
||||||
|
|
||||||
|
// wp_max_upload_size() can be expensive, so only call it when relevant for the current user.
|
||||||
|
$max_upload_size = 0;
|
||||||
|
if ( current_user_can( 'upload_files' ) ) {
|
||||||
$max_upload_size = wp_max_upload_size();
|
$max_upload_size = wp_max_upload_size();
|
||||||
if ( ! $max_upload_size ) {
|
if ( ! $max_upload_size ) {
|
||||||
$max_upload_size = 0;
|
$max_upload_size = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** This filter is documented in wp-admin/includes/media.php */
|
/** This filter is documented in wp-admin/includes/media.php */
|
||||||
$image_size_names = apply_filters(
|
$image_size_names = apply_filters(
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-alpha-54768';
|
$wp_version = '6.2-alpha-54769';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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