Created
July 17, 2013 08:08
-
-
Save sheabunge/6018680 to your computer and use it in GitHub Desktop.
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 in Comments | |
* Description: Allow oEmbeds in comment text. A fork of http://wordpress.org/plugins/oembed-in-comments/ | |
* Version: 1.2 | |
* Author: Evan Solomon, modified by Shea Bunge | |
*/ | |
class oEmbed_Comments { | |
static function init() { | |
if ( is_admin() ) | |
return; | |
$this->add_filter(); | |
} | |
/** | |
* Setup filter with correct priority to do oEmbed in comments | |
* | |
* @since 1.0 | |
* @uses add_filter To register a filter hook | |
* @uses has_filter() To check if a filter is registered | |
*/ | |
function add_filter() { | |
/* make_clickable breaks oEmbed regex, make sure we go earlier */ | |
$clickable = has_filter( 'comment_text', 'make_clickable' ); | |
$priority = ( $clickable ) ? $clickable - 1 : 10; | |
add_filter( 'comment_text', array( $this, 'oembed_filter' ), $priority ); | |
} | |
/** | |
* Safely add oEmbed media to a comment | |
*/ | |
function oembed_filter( $comment_text ) { | |
global $wp_embed; | |
// Automatic discovery would be a security risk, safety first | |
add_filter( 'embed_oembed_discover', '__return_false', 999 ); | |
$comment_text = $wp_embed->autoembed( $comment_text ); | |
// ...but don't break your posts if you use it | |
remove_filter( 'embed_oembed_discover', '__return_false', 999 ); | |
return $comment_text; | |
} | |
} | |
add_action( 'init', array( 'oEmbed_Comments', 'init' ) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment