Tag Archives: Vimeo

Vimeo oembed fix for WordPress (again!)

Either Vimeo or WordPress has changed something, but oembeds weren’t working for me with Vimeo. Some helpful people had produced patches in the form of plugins but they didn’t work either. However, they very nearly did. Here’s my corrected version of the plugin.


/*
Plugin Name: Vimeo oembed hotfix
Plugin URI:
Description: Enable https vimeo embeds. Note: If for any reason videos are not embedding properly, simply deactivate, and then reactivate this plugin. Note2: either Vimeo changed or something else went wrong but I had to update the line below with "oembed." in it.
Author: gluten, rowbory
Version: 2.1
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( 'https://vimeo.com/api/oembed.xml?{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' );

Download a zip of the tiny vimeo-oembed-fix plugin here.