clear_embed_cache not working for Multisite/Network
-
Hi,
while trying to solve another problem (I’ll make a separate post), I stumbled upon this bug in the clear_embed_cache function (inc/class-embed-privacy.php):
It seems that the code does not clear the postmeta tables from old embed-privacy entries on multisite installations. The code is here:
/** * Embeds are cached in the postmeta database table and need to be removed * whenever the plugin will be enabled or disabled. */ public function clear_embed_cache() { global $wpdb; // the query to delete cache $query = "DELETE FROM $wpdb->postmeta WHERE meta_key LIKE '%_oembed_%'"; if ( is_plugin_active_for_network( 'embed-privacy/embed-privacy.php' ) ) { // on networks we need to iterate through every site $sites = get_sites( 99999 ); foreach ( $sites as $site ) { switch_to_blog( $site ); $wpdb->query( $query ); } } else { $wpdb->query( $query ); } }The thing is, that the query is not updated to match the blogs’ individual postmeta table names. I tried my best coming up with a dynamic solution, but unfortunately I could not figure out a way to dynamically the table name, so instead I came up with this adapted query to be executed while in the foreach loop:
$query2 = "DELETE FROM ".$wpdb->get_blog_prefix($site->blog_id)."postmeta WHERE meta_key LIKE '%_oembed_%'";This query did successfully delete all the post meta data from all the blogs on dis-/reenabling the plugin on my multisite.
I think you also can skip the
switch_to_blogpart. Another way would be to use the delete_post_meta function but then you either have to loop over all post metas to find the keys you want to delete or store this information elsewhere.
The topic ‘clear_embed_cache not working for Multisite/Network’ is closed to new replies.