Skip to content

Instantly share code, notes, and snippets.

@sheabunge
Created July 17, 2013 08:08
Show Gist options
  • Save sheabunge/6018680 to your computer and use it in GitHub Desktop.
Save sheabunge/6018680 to your computer and use it in GitHub Desktop.
<?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