有没有内置的函数来查看URL是否与oEmbed兼容?

时间:2011-04-23 作者:Manny Fleurmond

我希望能够获取一个url,看看该域是否是Wordpress支持通过oEmbed添加嵌入的域之一。WordPress中是否有内置函数可以执行此操作,或者我是否需要创建自己的函数?

示例:如果我有一个视频网站的url,我希望能够检查该url,并能够判断该域是否受WordPress支持用于嵌入视频。

1 个回复
最合适的回答,由SO网友:fuxia 整理而成

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,
  ),
)

结束

相关推荐

无法访问wp-login.php时如何登录?

我在家里的virtbox服务器上安装了一个自托管wordpress<我在试wordpress的插件。在启用了一些安全插件之后,我发现我无法访问wp登录名。php页面<我得到一个插件的功能,告诉我这个网站是被禁止的,不存在<问题是,我不确定是哪个插件做的我在页面的前端也没有登录链接我安装的插件有防弹安全、锁定wp admin、终极安全检查器和wp安全扫描安装在没有GUI的ubuntu服务器上,主机是mac osx,但我可以从网络访问它<如果我只是从wordpress目录中删除插件,那