钩子文档

pre_wp_filesize

💡 云策文档标注

概述

pre_wp_filesize 是一个 WordPress 过滤器钩子,用于在 wp_filesize 函数执行前过滤其返回值。它允许开发者自定义文件大小计算逻辑,绕过默认的 PHP filesize 调用。

关键要点

  • pre_wp_filesize 钩子在 wp_filesize 函数运行前触发,用于修改或替换文件大小值。
  • 参数包括 $size(初始为 null,可返回整数以跳过 filesize 调用)和 $path(文件路径)。
  • 此钩子从 WordPress 6.0.0 版本开始引入,与 wp_filesize 函数相关。

代码示例

$size = apply_filters( 'pre_wp_filesize', null, $path );

📄 原文内容

Filters the result of wp_filesize before the PHP function is run.

Parameters

$sizenull|int
The unfiltered value. Returning an int from the callback bypasses the filesize call.
$pathstring
Path to the file.

Source

$size = apply_filters( 'pre_wp_filesize', null, $path );

Changelog

Version Description
6.0.0 Introduced.