wp_sprintf
云策文档标注
概述
本文档介绍了 wp_sprintf 函数中使用的过滤器,用于在格式化字符串时过滤模式片段。如果片段未被修改,将直接应用 sprintf() 处理。
关键要点
- wp_sprintf 过滤器允许开发者自定义传递给 wp_sprintf() 的模式片段处理逻辑。
- 过滤器接收两个参数:$fragment(模式片段字符串)和 $arg(参数字符串)。
- 如果过滤器未修改 $fragment,则默认使用 sprintf() 处理该片段。
- 此过滤器自 WordPress 2.5.0 版本引入,位于 wp-includes/formatting.php 文件中。
代码示例
$_fragment = apply_filters( 'wp_sprintf', $fragment, $arg );注意事项
- 使用此过滤器时,需确保正确处理 $fragment 和 $arg 参数,以避免格式化错误。
- 过滤器仅在 wp_sprintf() 函数内部调用,用于增强字符串格式化的灵活性。
原文内容
Filters a fragment from the pattern passed to wp_sprintf() .
Description
If the fragment is unchanged, then sprintf() will be run on the fragment.
Parameters
$fragmentstring-
A fragment from the pattern.
$argstring-
The argument.
Source
$_fragment = apply_filters( 'wp_sprintf', $fragment, $arg );
Changelog
| Version | Description |
|---|---|
| 2.5.0 | Introduced. |