Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Created February 28, 2013 05:51
Show Gist options
  • Save ninnypants/5054541 to your computer and use it in GitHub Desktop.
Save ninnypants/5054541 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 : [email protected])
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();
@jasperf
Copy link

jasperf commented Feb 14, 2020

Does work, but current editor still balks it could not embed a link like https://gist.github.com/jasperf/fa980ef3063dcd959553b069e2eaccee .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment