Make WordPress Core


Ignore:
Timestamp:
03/14/2022 04:30:35 PM (2 years ago)
Author:
hellofromTonya
Message:

Media: Relocate wp_filesize() function for use in frontend and backend.

A new function wp_filesize() was added with [52837]. The function lived in the wp-admin/includes/file.php file. However, this admin specific function is not loaded into memory when hitting media/edit endpoint. The result was a 500 Internal Server Error. Why? The function is invoked with that endpoint, but the function does not exist in memory.

This commit relocates the new function to the wp-includes/functions.php file. In doing so, the function is available for both the frontend and backend.

Follow-up to [52837].

Props talldanwp, spacedmonkey, costdev, antonvlasenko.
Fixes #55367.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/file.php

    r52837 r52932  
    263263        return $keys;
    264264    }
    265 
    266     /**
    267      * @ticket 49412
    268      * @covers ::wp_filesize
    269      */
    270     function test_wp_filesize_with_nonexistent_file() {
    271         $file = 'nonexistent/file.jpg';
    272         $this->assertEquals( 0, wp_filesize( $file ) );
    273     }
    274 
    275     /**
    276      * @ticket 49412
    277      * @covers ::wp_filesize
    278      */
    279     function test_wp_filesize() {
    280         $file = DIR_TESTDATA . '/images/test-image-upside-down.jpg';
    281 
    282         $this->assertEquals( filesize( $file ), wp_filesize( $file ) );
    283 
    284         $filter = function() {
    285             return 999;
    286         };
    287 
    288         add_filter( 'wp_filesize', $filter );
    289 
    290         $this->assertEquals( 999, wp_filesize( $file ) );
    291 
    292         $pre_filter = function() {
    293             return 111;
    294         };
    295 
    296         add_filter( 'pre_wp_filesize', $pre_filter );
    297 
    298         $this->assertEquals( 111, wp_filesize( $file ) );
    299     }
    300265}
Note: See TracChangeset for help on using the changeset viewer.