Created
April 28, 2011 10:38
-
-
Save miya0001/946144 to your computer and use it in GitHub Desktop.
oEmbed gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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