Skip to content

Instantly share code, notes, and snippets.

@jasperf
Forked from ninnypants/gist-oembed.php
Created February 14, 2020 01:20
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 jasperf/b36f928c645e8fb4ffe4073bf97fdb16 to your computer and use it in GitHub Desktop.
Save jasperf/b36f928c645e8fb4ffe4073bf97fdb16 to your computer and use it in GitHub Desktop.
Quick WordPress plugin to add gists to oEmbed
<?php
/*
Plugin Name: Gist oEmbed
Plugin URI: http://ninnypants.com
Description: Embed gists into posts
Version: 1.0
Author: ninnypants
Author URI: http://ninnypants.com
License: GPL2
Copyright 2013 Tyrel Kelsey (email : tyrel@ninnypants.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class Gists_oEmbed {
public function __construct(){
add_action( 'init', array( $this, 'setup_handler' ) );
}
public function gist_result( $url ){
$url = $url[0];
if( !preg_match( '#\.js$#i', $url ) )
$url .= '.js';
return '<script src="' . $url . '"></script>';
}
public function setup_handler(){
wp_embed_register_handler( 'gist', '#https?://gist.github.com/.*#i', array( $this, 'gist_result' ) );
}
}
$gists_oembed = new Gists_oEmbed();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment