WordPress refuses to show oembed URL

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:

Read More
<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?

Related posts

Leave a Reply

2 comments

  1. 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.