Created
October 13, 2011 17:09
-
-
Save samargulies/1284826 to your computer and use it in GitHub Desktop.
Vimeo oembed hotfix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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