钩子文档

pre_wp_unique_filename_file_list

💡 云策文档标注

概述

pre_wp_unique_filename_file_list 是一个 WordPress 过滤器,用于在计算新添加文件的唯一文件名时,过滤用于比较的文件列表。通过此过滤器,开发者可以自定义文件列表,从而绕过文件系统检索。

关键要点

  • 过滤器名称:pre_wp_unique_filename_file_list
  • 作用:过滤用于计算唯一文件名的文件列表,允许开发者提供自定义数组以替代从文件系统获取的列表
  • 参数:$files(数组或 null,默认 null 表示从文件系统检索)、$dir(字符串,新文件所在目录)、$filename(字符串,新文件的建议文件名)
  • 返回值:如果过滤器返回数组,将直接使用该数组进行文件名比较,跳过文件系统检索
  • 引入版本:WordPress 5.5.0
  • 相关函数:wp_unique_filename(),用于获取给定目录中经过清理且唯一的文件名

📄 原文内容

Filters the file list used for calculating a unique filename for a newly added file.

Description

Returning an array from the filter will effectively short-circuit retrieval from the filesystem and return the passed value instead.

Parameters

$filesarray|null
The list of files to use for filename comparisons.
Default null (to retrieve the list from the filesystem).
$dirstring
The directory for the new file.
$filenamestring
The proposed filename for the new file.

Source

$files = apply_filters( 'pre_wp_unique_filename_file_list', null, $dir, $filename );

Changelog

Version Description
5.5.0 Introduced.