One of the minor hassles of running WordPress Multisite is dealing with the rules about HTML cleansing- mainly the removal of iframe elements. You could install unfiltered MU but the plugin itself warns you that’s end-of-the-world dangerous and the plugin hasn’t been updated in two years. The combination might make one a bit nervous.
In this particular case, I have a group who wants to use videos from dotsub.com. Turns out it’s a good site for captioning and other things that make the video more accessible. This group is working on universal design so dotsub makes doubly good sense.
WordPress supports a number of sites using oEmbed. That’s the magic that allows you to paste in a YouTube URL and the embed codes are taken care of without you having to do anything. WordPress essentially run off a white list of sites that it accepts off the bat.
It turns out that oEmbed lists a bunch of sites that support the API and dotsub.com ended up being one of them.1 That means I just have to add dotsub.com to the WordPress install’s whitelist. The ever handy WordPress codex lets me know that I do that using wp_oembed_add_provider and further down on that page you’ll see that lives wp-includes/media.php.
I could have done it this way but I don’t like editing the core WordPress files for all sorts of reasons. One of them would be that I’d have to redo this every time WordPress updates. Another would be that I stand a much greater chance of seriously breaking something.
I figured I could write a plugin to do something similar. I have never written a plugin so I wandered around a bit looking for oEmbed plugins to use as an example. I found Codepen oEmbed relatively quickly.2 It is a dead simple plugin. It simply says (I left out the non-action stuff that says the name etc.) -
wp_oembed_add_provider( 'http://codepen.io/*/pen/*', 'http://codepen.io/api/oembed' );
That’s all there is to it. Who knew?3 Somehow I thought it’d be much harder and more involved.
wp_oembed_add_provider( 'http://dotsub.com/view/*', 'http://dotsub.com/services/oembed' );
dotsub.com had a handy page to help me get the structure straight. The first chunk is the URL structure and the second is the API endpoint on the site.
I haven’t done it yet but it seems like it’d be easy to keep adding URLS to this plugin to add additional oEmbed sites and it’d be fairly seamless. If wiser folk than I have better ways to do this, I’m all eyes, ears etc.