Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert bbPress 1 favorite topics into topic subscriptions in bbPress 2
<?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
You can’t perform that action at this time.