Skip to content

Instantly share code, notes, and snippets.

@nguyenvanduocit
Created September 4, 2015 15:24
Show Gist options
  • Save nguyenvanduocit/aadc8320e376ac64be35 to your computer and use it in GitHub Desktop.
Save nguyenvanduocit/aadc8320e376ac64be35 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: WP Gist oEmbed
Plugin URI: https://laptrinh.senviet.org
Description: Embed source from gist.github.
Author: nguyenvanduocit
Version: 1.9.0
Author URI: http://nvduoc.senviet.org
*/
class sv_gist_oembed {
private $regex = "/https:\\/\\/gist\\.github\\.com\\/([a-zA-Z0-9]*)\\/([a-z0-9]*)$/i";
function __construct()
{
wp_embed_register_handler(
'sv-gist-oembed',
$this->regex,
array( $this, 'handler' )
);
}
public function handler( $matches, $attr, $url, $rawattr )
{
return sprintf('<script src="https://gist.github.com/%1$s/%2$s.js"></script>', $matches[1], $matches[2]);
}
}
new sv_gist_oembed();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment