wp_oembed_ensure_format()
云策文档标注
概述
wp_oembed_ensure_format() 函数用于验证 oEmbed 响应格式,确保其仅接受 'json' 或 'xml' 值。如果输入无效,则默认返回 'json'。
关键要点
- 参数 $format 为必需字符串,指定 oEmbed 响应格式,仅接受 'json' 或 'xml'。
- 返回值是字符串,为 'xml' 或 'json',默认值为 'json'。
- 函数内部使用 in_array() 严格检查格式,无效时返回 'json'。
- 此函数自 WordPress 4.4.0 版本引入。
代码示例
function wp_oembed_ensure_format( $format ) {
if ( ! in_array( $format, array( 'json', 'xml' ), true ) ) {
return 'json';
}
return $format;
}
原文内容
Ensures that the specified format is either ‘json’ or ‘xml’.
Parameters
$formatstringrequired-
The oEmbed response format. Accepts
'json'or'xml'.
Source
function wp_oembed_ensure_format( $format ) {
if ( ! in_array( $format, array( 'json', 'xml' ), true ) ) {
return 'json';
}
return $format;
}
Changelog
| Version | Description |
|---|---|
| 4.4.0 | Introduced. |