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. Built from https://develop.svn.wordpress.org/trunk@52932 git-svn-id: http://core.svn.wordpress.org/trunk@52521 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
d1fe2eec5c
commit
316aa2544f
|
@ -2555,41 +2555,3 @@ function wp_opcache_invalidate( $filepath, $force = false ) {
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for PHP filesize with filters and casting the result as an integer.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @link https://www.php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param string $path Path to the file.
|
||||
* @return int The size of the file in bytes, or 0 in the event of an error.
|
||||
*/
|
||||
function wp_filesize( $path ) {
|
||||
/**
|
||||
* Filters the result of wp_filesize before the PHP function is run.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
|
||||
* @param string $path Path to the file.
|
||||
*/
|
||||
$size = apply_filters( 'pre_wp_filesize', null, $path );
|
||||
|
||||
if ( is_int( $size ) ) {
|
||||
return $size;
|
||||
}
|
||||
|
||||
$size = (int) @filesize( $path );
|
||||
|
||||
/**
|
||||
* Filters the size of the file.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param int $size The result of PHP filesize on the file.
|
||||
* @param string $path Path to the file.
|
||||
*/
|
||||
return (int) apply_filters( 'wp_filesize', $size, $path );
|
||||
}
|
||||
|
|
|
@ -3458,6 +3458,44 @@ function wp_get_ext_types() {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper for PHP filesize with filters and casting the result as an integer.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @link https://www.php.net/manual/en/function.filesize.php
|
||||
*
|
||||
* @param string $path Path to the file.
|
||||
* @return int The size of the file in bytes, or 0 in the event of an error.
|
||||
*/
|
||||
function wp_filesize( $path ) {
|
||||
/**
|
||||
* Filters the result of wp_filesize before the PHP function is run.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
|
||||
* @param string $path Path to the file.
|
||||
*/
|
||||
$size = apply_filters( 'pre_wp_filesize', null, $path );
|
||||
|
||||
if ( is_int( $size ) ) {
|
||||
return $size;
|
||||
}
|
||||
|
||||
$size = (int) @filesize( $path );
|
||||
|
||||
/**
|
||||
* Filters the size of the file.
|
||||
*
|
||||
* @since 6.0.0
|
||||
*
|
||||
* @param int $size The result of PHP filesize on the file.
|
||||
* @param string $path Path to the file.
|
||||
*/
|
||||
return (int) apply_filters( 'wp_filesize', $size, $path );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve list of allowed mime types and file extensions.
|
||||
*
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.0-alpha-52931';
|
||||
$wp_version = '6.0-alpha-52932';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue