Created
May 24, 2016 14:34
-
-
Save foliovision/58d1899b841ecc837dc348483d7a158d to your computer and use it in GitHub Desktop.
Convert bbPress 1 favorite topics into topic subscriptions in bbPress 2
This file contains hidden or 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 | |
include('wp-load.php'); | |
global $wpdb; | |
$aUsers = $wpdb->get_results("SELECT user_id,meta_value FROM $wpdb->usermeta WHERE meta_key = 'bb_favorites'"); | |
$i = 0; | |
foreach($aUsers as $user){ | |
$i++; | |
$sTopics = $user->meta_value; | |
$aTopics = explode(',',$sTopics); | |
$sUser_name = $wpdb->get_col("SELECT user_login FROM $wpdb->users WHERE ID=$user->user_id"); | |
echo "USER: ".$sUser_name[0]." (".$user->user_id.")</br>"; | |
$sSubscriptions = ""; | |
foreach($aTopics as $sOld_topic_id){ | |
echo "Old topic id :".$sOld_topic_id."</br>"; | |
if(strlen($sOld_topic_id)>0){ | |
$sTopic_id = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = $sOld_topic_id AND meta_key='_bbp_old_topic_id'"); | |
$sSubscriptions .= $sTopic_id[0].","; | |
} | |
} | |
$sSubscriptions = trim($sSubscriptions,","); | |
echo "NEW SUBSCRIPTIONS: ".$sSubscriptions."</br>"; | |
$res = add_user_meta($user->user_id, "wp__bbp_subscriptions", $sSubscriptions ); | |
if($res == false){ | |
echo "META KEY WASN'T INSRETED!</br>"; | |
} else{ | |
echo "META KEY WAS INSERTED!</br>"; | |
} | |
} | |
echo "SUBSCRIPTIONS FOR $i USERS WERE UPDATED FROM bb_favorites TO wp__bbp_subscriptions</br>"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment