Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to be able to take a url and see if the domain is one of the ones Wordpress supports to add embeds via oEmbed. Is there a built in function that does this in WordPress or would I need to create my own?

Example: if I have a url from a video site I want to be able to examine the url and be able to tell if the domain is supported by WordPress for use to embed as a video.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

wp-includes/class-oembed.php has a public variable $providers. So you can build a small function to get all of them:

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;
}

If you call this function …

list_oembed_providers();

… you get in 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,
  ),
)
share|improve this answer
    
Are those indexes regular expressions? –  Manny Fleurmond Apr 24 '11 at 2:06
    
The second sub-array entry will tell you: if it is false like with 'http://youtu.be/* or 'http://qik.com/*' it is not a regex. Look into wp-includes/class-oembed.php function get_html() to see how it is used. –  toscho Apr 24 '11 at 2:27
    
And thank you. That does the trick nicely –  Manny Fleurmond Apr 24 '11 at 2:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.