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 need WP to show an embedded representation of a url such as http://domain.com/1121 using oembed.

I have setup http://domain.com/1121 with a discovery link:

<link href="http://www.domain.com/generator/oembed/?url=http%3A//domain.com/1121" rel="alternate" type="text/xml+oembed" />

I'm aware that WP no longer automatically discovers embeddable URLs, so I installed enable-oembed-discovery plugin to re-enable this feature.

I have monitored my apache logs and confirmed that WP does hits the link to discover - so I guess the enable-oembed-discovery plugin works, but the URL is NEVER converted.

I even wrote a plugin to whitelist my custom URL (really should not be needed since enable-oembed-discovery plugin should enable auto-discovery, but what the heck):

add_action( 'init', 'my_oembed_provider' );

function my_oembed_provider() {
    wp_oembed_add_provider( 'http://domain.com/*', 'http://www.domain.com/generator/oembed/', false);
}

and still nothing.

The API endpoint (http://www.domain.com/generator/oembed/) is hard coded to generate the following XML:

        <?xml version="1.0" encoding="UTF-8"?>
        <OEmbed>
            <type>rich</type>
            <width>400</width>
            <height>342</height>
            <html><![CDATA[&lt;b&gt;HELLO WORLD FROM OEMBED &lt;/b&gt;]]></html>
        </OEmbed>

The API endpoint sends the right content-type header (header("Content-type: text/xml");) as required by the oembed spec

The user adding the post has admin privileges and therefore is allowed unfiltered_html

I'm out of ideas and at wit's end. What am I missing?

share|improve this question
add comment

2 Answers 2

up vote 2 down vote accepted

Your XML root element was 'OEmbed', not 'oembed', as given in the spec. XML element names are case-sensitive, per the XML spec.

share|improve this answer
    
o_0 I missed that completely.. this is technically the right answer for my problem. Thank you. –  Jahufar Jul 1 '11 at 4:40
add comment

Two things:

  1. WordPress' oEmbed implementation prefers and works better with JSON.

  2. To use XML, WordPress needs the simplexml library in PHP to be available. If it's not available, then you'd probably get the results you're seeing. It's getting the XML but can't parse it without simplexml, so... nothing happens.

Best way to fix the problem: Stop trying to use XML. Use JSON instead.

The link type would be application/json+oembed.

The endpoint would return json data (using a content type of application/json):

{
"type":"rich",
"width":"400",
"height":"342",
"html":"&lt;b&gt;HELLO WORLD FROM OEMBED &lt;/b&gt;"
}

Things tend to work better that way. JSON is the preferred format for oEmbed with all providers.

share|improve this answer
1  
Yeah, I was looking through the code (tig12.net/downloads/apidocs/wp3/wp-includes/…) a few mins back and the comments seem to indicate this. I'll change my endpoint to echo back JSON and see if it helps. Also: my config has simpleXml lib installed.. so XML parser should kick in –  Jahufar Jun 30 '11 at 11:26
    
I can't believe I spent all morning and most of the afternoon chasing after this. Implementing this in JSON as you said just solved it. Why on earth is there code that handles XML endpoints in WP's codebase when it doesn't obviously work?! Anyways, thanks a lot! –  Jahufar Jun 30 '11 at 11:46
add comment

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.