• Resolved Fiech

    (@fiech)


    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_blog part. 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.

Viewing 1 replies (of 1 total)
  • Plugin Author Matthias Kittsteiner

    (@kittmedia)

    Hi there!

    Thank you for digging into the problem and providing a solution. We will ship this fix in the next release.

    Just as a quick note regarding to delete_post_meta: We used a custom query for performance reason to not be forced to iterate over each post, which would be dramatically slower.

Viewing 1 replies (of 1 total)

The topic ‘clear_embed_cache not working for Multisite/Network’ is closed to new replies.