Skip to content

Instantly share code, notes, and snippets.

@samargulies
Created October 13, 2011 17:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save samargulies/1284826 to your computer and use it in GitHub Desktop.
Save samargulies/1284826 to your computer and use it in GitHub Desktop.
Vimeo oembed hotfix
<?php
/*
Plugin Name: Vimeo oembed hotfix
Plugin URI:
Description: Enable https vimeo embeds. <strong>Note</strong>: If for any reason videos are not embedding properly, simply deactivate, and then reactivate this plugin.
Author: gluten
Version: 2.0
Author URI: http://belabor.org/
*/
function oembed_hotfix_vimeo_oembed_providers( $providers ) {
unset($providers['#http://(www\.)?vimeo\.com/.*#i']);
$providers['#https?://(www\.)?vimeo\.com/.*#i'] = array( 'http://vimeo.com/api/oembed.{format}', true );
return $providers;
}
add_filter('oembed_providers', 'oembed_hotfix_vimeo_oembed_providers');
// based on this patch: http://core.trac.wordpress.org/attachment/ticket/10337/10337.10.patch
function oembed_hotfix_delete_all_oembed_caches() {
// Based on delete_post_meta_by_key()
global $wpdb;
$post_ids = $wpdb->get_col( "SELECT DISTINCT post_id FROM $wpdb->postmeta WHERE meta_key LIKE '_oembed_%'" );
if ( $post_ids ) {
$postmetaids = $wpdb->get_col( "SELECT meta_id FROM $wpdb->postmeta WHERE meta_key LIKE '_oembed_%'" );
$in = implode( ',', array_fill( 1, count($postmetaids), '%d' ) );
do_action( 'delete_postmeta', $postmetaids );
$wpdb->query( $wpdb->prepare( "DELETE FROM $wpdb->postmeta WHERE meta_id IN($in)", $postmetaids ) );
do_action( 'deleted_postmeta', $postmetaids );
foreach ( $post_ids as $post_id )
wp_cache_delete( $post_id, 'post_meta' );
return true;
}
return false;
}
register_activation_hook( __FILE__, 'oembed_hotfix_delete_all_oembed_caches' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment