public
Last active

Vimeo oembed hotfix

  • Download Gist
oembed-hotfix.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<?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' );
 
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.