是否有内置功能来查看URLI是否兼容?
题
我希望能够使用一个URL,看看该域是否是WordPress支持的域之一,可以通过OEMBED添加嵌入。是否有内置函数可以在WordPress中执行此操作,或者我需要创建自己的功能?
示例:如果我从视频网站上有一个URL,我希望能够检查URL,并能够判断WordPress支持该域是否支持将其用作视频。
解决方案
wp-includes/class-oembed.php
有公共变量 $providers
. 。因此,您可以构建一个小功能以获取所有功能:
function list_oembed_providers( $print = TRUE )
{
require_once( ABSPATH . WPINC . '/class-oembed.php' );
$oembed = _wp_oembed_get_object();
$print and print '<pre>' . htmlspecialchars( var_export( $oembed->providers, TRUE ) ) . '</pre>';
return $oembed->providers;
}
如果您调用此功能…
list_oembed_providers();
…您进入WordPress 3.1.1:
array (
'#http://(www\\.)?youtube.com/watch.*#i' =>
array (
0 => 'http://www.youtube.com/oembed',
1 => true,
),
'http://youtu.be/*' =>
array (
0 => 'http://www.youtube.com/oembed',
1 => false,
),
'http://blip.tv/file/*' =>
array (
0 => 'http://blip.tv/oembed/',
1 => false,
),
'#http://(www\\.)?vimeo\\.com/.*#i' =>
array (
0 => 'http://www.vimeo.com/api/oembed.{format}',
1 => true,
),
'#http://(www\\.)?dailymotion\\.com/.*#i' =>
array (
0 => 'http://www.dailymotion.com/api/oembed',
1 => true,
),
'#http://(www\\.)?flickr\\.com/.*#i' =>
array (
0 => 'http://www.flickr.com/services/oembed/',
1 => true,
),
'#http://(.+)?smugmug\\.com/.*#i' =>
array (
0 => 'http://api.smugmug.com/services/oembed/',
1 => true,
),
'#http://(www\\.)?hulu\\.com/watch/.*#i' =>
array (
0 => 'http://www.hulu.com/api/oembed.{format}',
1 => true,
),
'#http://(www\\.)?viddler\\.com/.*#i' =>
array (
0 => 'http://lab.viddler.com/services/oembed/',
1 => true,
),
'http://qik.com/*' =>
array (
0 => 'http://qik.com/api/oembed.{format}',
1 => false,
),
'http://revision3.com/*' =>
array (
0 => 'http://revision3.com/api/oembed/',
1 => false,
),
'http://i*.photobucket.com/albums/*' =>
array (
0 => 'http://photobucket.com/oembed',
1 => false,
),
'http://gi*.photobucket.com/groups/*' =>
array (
0 => 'http://photobucket.com/oembed',
1 => false,
),
'#http://(www\\.)?scribd\\.com/.*#i' =>
array (
0 => 'http://www.scribd.com/services/oembed',
1 => true,
),
'http://wordpress.tv/*' =>
array (
0 => 'http://wordpress.tv/oembed/',
1 => false,
),
'#http://(answers|surveys)\\.polldaddy.com/.*#i' =>
array (
0 => 'http://polldaddy.com/oembed/',
1 => true,
),
'#http://(www\\.)?funnyordie\\.com/videos/.*#i' =>
array (
0 => 'http://www.funnyordie.com/oembed',
1 => true,
),
)