Skip to content

Instantly share code, notes, and snippets.

@miya0001
Created April 28, 2011 10:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miya0001/946144 to your computer and use it in GitHub Desktop.
Save miya0001/946144 to your computer and use it in GitHub Desktop.
oEmbed gist
<?php
/*
Plugin Name: oEmbed gist
Plugin URI: http://firegoby.theta.ne.jp/wp/oembed-gist
Description: Embed source from gist.github.
Author: Takayuki Miyauchi (THETA NETWORKS Co,.Ltd)
Version: 0.1.0
Author URI: http://firegoby.theta.ne.jp/
*/
new gist();
class gist {
private $html = '<script src="https://gist.github.com/%s.js"></script>';
function __construct()
{
wp_embed_register_handler(
'gist',
'#https://gist.github.com/([0-9]+)#i',
array(&$this, 'handler')
);
add_shortcode('gist', array(&$this, 'shortcode'));
}
public function handler($m, $attr, $url, $rattr)
{
return '[gist id="'.$m[1].'"]';
}
public function shortcode($p)
{
if (preg_match("/^[0-9]+$/", $p['id'])) {
return sprintf($this->html, $p['id']);
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment