Bloated wp_usermeta table

We have a Multisite installation using the New Blog Templates plugin. The table wp_usermeta has over 98,000 entries for only 10 sites. We have tried using the following function in the functions file with no success. add_filter('wp','cleanup');
function cleanup() {
error_log("cleanup");
global $wpdb;
$dups = $wpdb->get_results( "SELECT *, COUNT(umeta_id) AS n FROM {$wpdb->usermeta} GROUP BY user_id, meta_key HAVING n > 1");

foreach( $dups as $dup ) {
$wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->usermeta} WHERE user_id = %d AND meta_key = %s AND umeta_id <> %d",
$dup->user_id, $dup->meta_key, $dup->umeta_id ) );
}
}
We can't upgrade to the newest version because we would have to upgrade hundreds of installations to make this work correctly.

Is there any way to clean duplicate entries in the wp_usermeta table without breaking the installation?

This is not an install issue it is an issue with your blog theme template plugin. It creates thousands of peices of duplicate user meta. it has an issue with "_" so you see meta values like:
wp_11_10_9_8_7_6_5_4_3_2user_level
wp_11_10_9_8_7_6_5_4_3user_level
wp_11_10_9_8_7_6_5_4user_level
wp_11_10_9_8_7_6_5user_level
wp_11_10_9_8_7_6user_level

and so one for every meta value. The fix we found on your forum didn't work it's the code above. and doesn't find these duplicates.

It has done this pattern every time a site is made making the total results = 97,307 before we ran the code above the wp_user_meta table had over 170,000 results.

We need a function to clean these tables so we can keep the sites running properly without doing an upgrade to wp 3.3.1

How do you rate me?

Thank you for rating your experience!

We’re thrilled to hear you had a great experience with . Would you like to leave a comment about your experience?
Thanks for voting on your experience with , we’d love to get some feedback please.
Ohh no! We’re really sorry to hear you didn’t have a pleasant experience with , we’re always looking at how we can improve and would appreciate you provide some further feedback here please.
Type your feedback here

it's great that you had a positive one. Based on your experience in this ticket would you please be kind enough to rate us externally on: