From 316aa2544f4c1ac033ac4cf014603898845f9f77 Mon Sep 17 00:00:00 2001 From: hellofromTonya Date: Mon, 14 Mar 2022 16:32:06 +0000 Subject: [PATCH] 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 --- wp-admin/includes/file.php | 38 -------------------------------------- wp-includes/functions.php | 38 ++++++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/wp-admin/includes/file.php b/wp-admin/includes/file.php index 759b0974bb..ddd2be849a 100644 --- a/wp-admin/includes/file.php +++ b/wp-admin/includes/file.php @@ -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 ); -} diff --git a/wp-includes/functions.php b/wp-includes/functions.php index a2c1650c49..a93285c5fc 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -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. * diff --git a/wp-includes/version.php b/wp-includes/version.php index 4b96462cff..8dd64b4bb5 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -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.