wp_oembed_remove_provider()
云策文档标注
概述
wp_oembed_remove_provider() 函数用于从 WordPress 中移除一个 oEmbed 提供程序。它接受一个 URL 格式字符串作为参数,并返回布尔值表示移除是否成功。
关键要点
- 参数 $format 是必需的,为要移除的 oEmbed 提供程序的 URL 格式字符串。
- 返回值是布尔类型,true 表示成功移除,false 表示失败。
- 函数内部根据 plugins_loaded 动作是否已触发,调用不同的移除逻辑。
- 如果 plugins_loaded 已触发,则通过 _wp_oembed_get_object() 获取 WP_oEmbed 对象并操作 providers 数组。
- 否则,调用 WP_oEmbed::_remove_provider_early() 进行早期移除。
代码示例
wp_oembed_remove_provider( 'http://wordpress.tv/*' );注意事项
- $format 参数必须是正则表达式字符串,且需与 class-wp-oembed.php 中的格式完全匹配,例如 "#https?://wordpress.tv/.*#i"。
- 移除操作应在适当时机执行,以避免影响其他功能。
原文内容
Removes an oEmbed provider.
Description
See also
Parameters
$formatstringrequired-
The URL format for the oEmbed provider to remove.
Source
function wp_oembed_remove_provider( $format ) {
if ( did_action( 'plugins_loaded' ) ) {
$oembed = _wp_oembed_get_object();
if ( isset( $oembed->providers[ $format ] ) ) {
unset( $oembed->providers[ $format ] );
return true;
}
} else {
WP_oEmbed::_remove_provider_early( $format );
}
return false;
}
Changelog
| Version | Description |
|---|---|
| 3.5.0 | Introduced. |
Skip to note 2 content
Codex
Removes the WordPress TV provider
wp_oembed_remove_provider( 'http://wordpress.tv/*' );"#https?://wordpress.tv/.*#i"