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.

git-svn-id: https://develop.svn.wordpress.org/trunk@52932 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Tonya Mork
2022-03-14 16:30:35 +00:00
parent 3bbfc064e9
commit f6b39a9d66
4 changed files with 73 additions and 73 deletions

View File

@@ -2106,4 +2106,39 @@ class Tests_Functions extends WP_UnitTestCase {
$this->assertFalse( wp_get_default_extension_for_mime_type( 123 ), 'false not returned when int as mime type supplied' );
$this->assertFalse( wp_get_default_extension_for_mime_type( null ), 'false not returned when null as mime type supplied' );
}
/**
* @ticket 49412
* @covers ::wp_filesize
*/
function test_wp_filesize_with_nonexistent_file() {
$file = 'nonexistent/file.jpg';
$this->assertEquals( 0, wp_filesize( $file ) );
}
/**
* @ticket 49412
* @covers ::wp_filesize
*/
function test_wp_filesize() {
$file = DIR_TESTDATA . '/images/test-image-upside-down.jpg';
$this->assertEquals( filesize( $file ), wp_filesize( $file ) );
$filter = function() {
return 999;
};
add_filter( 'wp_filesize', $filter );
$this->assertEquals( 999, wp_filesize( $file ) );
$pre_filter = function() {
return 111;
};
add_filter( 'pre_wp_filesize', $pre_filter );
$this->assertEquals( 111, wp_filesize( $file ) );
}
}