钩子文档

pre_get_language_files_from_path

💡 云策文档标注

概述

pre_get_language_files_from_path 是一个 WordPress 过滤器,用于在从指定路径检索翻译文件之前进行过滤。它允许开发者拦截并自定义翻译文件的查找过程,以优化性能或实现特定逻辑。

关键要点

  • 过滤器名称:pre_get_language_files_from_path
  • 作用:在翻译文件查找前过滤文件列表,返回非空值可短路默认查找流程
  • 参数:$files(null 或数组,默认 null)和 $path(字符串,翻译文件路径)
  • 性能优化:适用于目录包含大量文件时,避免默认 glob() 函数的性能开销
  • 相关函数:WP_Textdomain_Registry::get_language_files_from_path()
  • 引入版本:WordPress 6.5.0

📄 原文内容

Filters the translation files retrieved from a specified path before the actual lookup.

Description

Returning a non-null value from the filter will effectively short-circuit the MO files lookup, returning that value instead.

This can be useful in situations where the directory contains a large number of files and the default glob() function becomes expensive in terms of performance.

Parameters

$filesnull|array
List of translation files. Default null.
$pathstring
The path from which translation files are being fetched.

Source

$files = apply_filters( 'pre_get_language_files_from_path', null, $path );

Changelog

Version Description
6.5.0 Introduced.