On this page
wp_filesize( string $path ): int
Wrapper for PHP filesize with filters and casting the result as an integer.
Parameters
$pathstring Required-
Path to the file.
Return
int The size of the file in bytes, or 0 in the event of an error.
Source
File: wp-includes/functions.php. View all references
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 = file_exists( $path ) ? (int) filesize( $path ) : 0;
/**
* 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 );
}
Hooks
- apply_filters( 'pre_wp_filesize',
null|int $size ,string $path ) -
Filters the result of wp_filesize before the PHP function is run.
- apply_filters( 'wp_filesize',
int $size ,string $path ) -
Filters the size of the file.
Related
Uses
| Uses | Description |
|---|---|
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Used By
| Used By | Description |
|---|---|
| _wp_image_meta_replace_original() wp-admin/includes/image.php | Updates the attached file and image meta data when the original image was edited. |
| wp_create_image_subsizes() wp-admin/includes/image.php | Creates image sub-sizes, adds the new data to the image meta |
| wp_generate_attachment_metadata() wp-admin/includes/image.php | Generates attachment meta data and create image sub-sizes for images. |
| attachment_submitbox_metadata() wp-admin/includes/media.php | Displays non-editable attachment metadata in the publish meta box. |
| WP_Image_Editor_Imagick::_save() wp-includes/class-wp-image-editor-imagick.php | |
| WP_Image_Editor_GD::_save() wp-includes/class-wp-image-editor-gd.php | |
| wp_prepare_attachment_for_js() wp-includes/media.php | Prepares an attachment post object for JS, where it is expected to be JSON-encoded and fit into an Attachment model. |
Changelog
| Version | Description |
|---|---|
| 6.0.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_filesize