钩子文档

translation_file_format

💡 云策文档标注

概述

本文档介绍 WordPress 中的 translation_file_format 过滤器,用于控制翻译文件的首选格式,例如 PHP 或 MO 文件。开发者可以利用此过滤器禁用 PHP 翻译文件,以增强安全性或满足特定需求。

关键要点

  • translation_file_format 过滤器允许修改翻译文件的首选格式,可选值为 'php' 或 'mo',默认值为 'php'。
  • 过滤器接受两个参数:$preferred_format(首选格式字符串)和 $domain(文本域),可用于基于文本域定制格式。
  • 此过滤器在 load_textdomain() 函数中被调用,影响 .mo 文件的加载行为,自 WordPress 6.5.0 版本引入。

代码示例

$preferred_format = apply_filters( 'translation_file_format', 'php', $domain );

注意事项

  • 使用此过滤器可以禁用 PHP 翻译文件,有助于减少潜在的安全风险,因为 PHP 文件可能包含可执行代码。
  • 开发者应确保在适当的钩子或函数中应用此过滤器,以避免影响其他翻译功能。

📄 原文内容

Filters the preferred file format for translation files.

Description

Can be used to disable the use of PHP files for translations.

Parameters

$preferred_formatstring
Preferred file format. Possible values: 'php', 'mo'. Default: 'php'.
$domainstring
The text domain.

Source

$preferred_format = apply_filters( 'translation_file_format', 'php', $domain );

Changelog

Version Description
6.5.0 Introduced.