Changeset 54769
- Timestamp:
- 11/09/2022 12:28:33 AM (2 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/block-editor.php
r54291 r54769 154 154 function get_default_block_editor_settings() { 155 155 // 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 } 159 164 } 160 165 -
trunk/tests/phpunit/tests/blocks/editor.php
r54162 r54769 300 300 $this->assertIsInt( $settings['maxUploadFileSize'] ); 301 301 $this->assertTrue( $settings['__unstableGalleryWithImageBlocks'] ); 302 } 303 304 /** 305 * @ticket 56815 306 */ 307 public function test_get_default_block_editor_settings_max_upload_file_size() { 308 // Force the return value of wp_max_upload_size() to be 500. 309 add_filter( 310 'upload_size_limit', 311 function() { 312 return 500; 313 } 314 ); 315 316 // Expect 0 when user is not allowed to upload (as wp_max_upload_size() should not be called). 317 $settings = get_default_block_editor_settings(); 318 $this->assertSame( 0, $settings['maxUploadFileSize'] ); 319 320 // Set up an administrator, as they can upload files. 321 $administrator = self::factory()->user->create( array( 'role' => 'administrator' ) ); 322 wp_set_current_user( $administrator ); 323 324 // Expect the above 500 as the user is now allowed to upload. 325 $settings = get_default_block_editor_settings(); 326 $this->assertSame( 500, $settings['maxUploadFileSize'] ); 302 327 } 303 328
Note: See TracChangeset
for help on using the changeset viewer.