Make WordPress Core


Ignore:
Timestamp:
11/09/2022 01:06:46 AM (4 years ago)
Author:
flixos90
Message:

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.
Merges [54769] to the 6.1 branch.
Fixes #56815.

Location:
branches/6.1
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/6.1

  • branches/6.1/src/wp-includes/block-editor.php

    r54291 r54772  
    154154function get_default_block_editor_settings() {
    155155        // Media settings.
    156         $max_upload_size = wp_max_upload_size();
    157         if ( ! $max_upload_size ) {
    158                 $max_upload_size = 0;
     156
     157        // wp_max_upload_size() can be expensive, so only call it when relevant for the current user.
     158        $max_upload_size = 0;
     159        if ( current_user_can( 'upload_files' ) ) {
     160                $max_upload_size = wp_max_upload_size();
     161                if ( ! $max_upload_size ) {
     162                        $max_upload_size = 0;
     163                }
    159164        }
    160165
Note: See TracChangeset for help on using the changeset viewer.