TUTORIAL: Adding an oEmbed Provider to WordPress

I don’t often write tutorials. I probably should. But normally it’s only when someone asks me something and I think, “Hey, self… you should write up how to do this”. As if a book wasn’t enough.

Last night I was at the Austin Web Holiday party, a gathering of some 15+ technical meetup groups cross-pollinating over beer and socializing. I was introduced to one guy (can’t remember his name!) who had built a video site and enabled it for oEmbed. He couldn’t understand why WordPress wouldn’t just automatically let users use his videos, like it does for YouTube, Vimeo, etc. The full list of default oEmbed providers are listed here.

WordPress doesn’t allow automatic use of oEmbed for security reasons. Otherwise, someone could build a video service stuffed with malicious code that could potentially access your database or create a man in the middle attack or worse. WordPress.com certainly doesn’t allow arbitrary oEmbed sites and the dot-org open source software doesn’t allow arbitrary stuff automatically. But it can be done, on the dot-org side, with a plugin. All it is a hook.

Here’s an example. If you want to register an oEmbed video site that is, say, at (randomly) http:/mysuperawesomevideosite.com and your videos are of the format http://mysuperawesomevideosite.com/video/*, it’s as simple as adding a function in your plugin (or more properly from a PHP perspective, a method in a class – but that’s a personal preference. The method/function should call the  wp_oembed_add_provider() function.

In it’s simplest form, all you have to do is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class My_Plugin {

  var $oembed_endpoint;
  var $oembed_format;

  function __construct()
  {
    $this->oembed_endpoint = 'http://mysuperawesomevideosite.com';
    $this->oembed_format = 'http://mysuperawesomevideosite.com/video/*';

    $this->new_oembed();
  }

  function __destruct() {}

  function new_oembed()
  {
    wp_oembed_add_provider( $this->oembed_format, $this->oembed_endpoint );
  }

}

Then, to make this code work, just instantiate the class somewhere.

1
$my_plugin = new My_Plugin;

Voila!

Changing Roles at WP Engine

For some time, I’ve felt there was a change coming and today, I’m ready to announce that my role within WP Engine is changing. Starting today, I have transitioned into an advisory and consulting role with the company.

Effective immediately, I will be taking the portion of the business that focused on professional services and consulting to allow the company to focus on premiere WordPress hosting. It’s a good thing and I’m excited about the possibilities. Back in November, we decided to start taking on some professional services work to augment demands from many of our customers. It was awesome to have fast, secure, scaleable, managed hosting but they wanted more!

And we wanted more.

However, as the company has evolved, taken funding, hired more people, addressed growth challenges and built out our hosting option, it seemed clear that the professional services portion of the company was a separate kind of deal than what we wanted to focus on.

So today, I’ll be taking that portion of the company (and all related existing and current relationships, as agreed on), and working on that. Meanwhile, I’ll still be working with the company to guide direction and strategy. So it’s good for everyone.

Effective immediately, I am available for all WordPress consulting roles. However, I am also currently entertaining all possibilities involving full time employment as well, and welcome those conversations.

To contact me, please direct emails to aaron@technosailor.com. As transitions go, the immediate financial impact is something that I need to consider.