Make WordPress Core


Ignore:
Timestamp:
03/14/2022 04:30:35 PM (4 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/src/wp-admin/includes/file.php

    r52837 r52932  
    25562556    return false;
    25572557}
    2558 
    2559 /**
    2560  * Wrapper for PHP filesize with filters and casting the result as an integer.
    2561  *
    2562  * @since 6.0.0
    2563  *
    2564  * @link https://www.php.net/manual/en/function.filesize.php
    2565  *
    2566  * @param string $path Path to the file.
    2567  * @return int The size of the file in bytes, or 0 in the event of an error.
    2568  */
    2569 function wp_filesize( $path ) {
    2570     /**
    2571      * Filters the result of wp_filesize before the PHP function is run.
    2572      *
    2573      * @since 6.0.0
    2574      *
    2575      * @param null|int $size The unfiltered value. Returning an int from the callback bypasses the filesize call.
    2576      * @param string   $path Path to the file.
    2577      */
    2578     $size = apply_filters( 'pre_wp_filesize', null, $path );
    2579 
    2580     if ( is_int( $size ) ) {
    2581         return $size;
    2582     }
    2583 
    2584     $size = (int) @filesize( $path );
    2585 
    2586     /**
    2587      * Filters the size of the file.
    2588      *
    2589      * @since 6.0.0
    2590      *
    2591      * @param int    $size The result of PHP filesize on the file.
    2592      * @param string $path Path to the file.
    2593      */
    2594     return (int) apply_filters( 'wp_filesize', $size, $path );
    2595 }
Note: See TracChangeset for help on using the changeset viewer.