1

I've got two websites, a staging and a production one. They have 99% the same setup and are hosted on the same server. They are multi-site WP installs.

The issue that I've been trying to solve all morning is this: On one website oEmbed for comments works fine, but on the other one it does not work at all - it just spits out the raw urls.

I tried everything. I stripped the the site to bare-bones. I deactivated all plugins. Nothing seems to make it work and I'm now, very embarrassingly, clueless as of what might cause this discrepancy.

Any clue, help or idea is very much appreciated.

1 Answer 1

2

You can use the oEmbed in Comments plugin. This is the code the author, Evan Solomon, uses in this plugin, I used it on a site a while back just copy it in your themes functions file or even better, download his plugin :-)

class ES_oEmbed_Comments {

function __construct() {
add_action( 'init', array( $this, 'init' ) );
}

function init() {
if ( is_admin() )
return;

$this->add_filter();
}

/**
* Setup filter with correct priority to do oEmbed in comments
*/
function add_filter() {
// make_clickable breaks oEmbed regex, make sure we go earlier
$clickable = has_filter( 'get_comment_text', 'make_clickable' );
$priority = ( $clickable ) ? $clickable - 1 : 10;

add_filter( 'get_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;
}
}

new ES_oEmbed_Comments;
1
  • Yeah, I ended up using that. But the real question is why the heck would embeds work on a site without this plugin? :)
    – Banago
    Commented Jun 24, 2014 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.