Advertisement
Guest User

Untitled

a guest
May 24th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. <?php
  2.  
  3. include('wp-load.php');
  4.  
  5. global $wpdb;
  6. $aUsers = $wpdb->get_results("SELECT user_id,meta_value FROM $wpdb->usermeta WHERE meta_key = 'bb_favorites'");
  7. $i = 0;
  8.  
  9. foreach($aUsers as $user){
  10.  
  11. $i++;
  12. $sTopics = $user->meta_value;
  13. $aTopics = explode(',',$sTopics);
  14. $sUser_name = $wpdb->get_col("SELECT user_login FROM $wpdb->users WHERE ID=$user->user_id");
  15. echo "USER: ".$sUser_name[0]." (".$user->user_id.")</br>";
  16. $sSubscriptions = "";
  17.  
  18. foreach($aTopics as $sOld_topic_id){
  19. echo "Old topic id :".$sOld_topic_id."</br>";
  20. if(strlen($sOld_topic_id)>0){
  21. $sTopic_id = $wpdb->get_col("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = $sOld_topic_id AND meta_key='_bbp_old_topic_id'");
  22. $sSubscriptions .= $sTopic_id[0].",";
  23. }
  24. }
  25.  
  26. $sSubscriptions = trim($sSubscriptions,",");
  27. echo "NEW SUBSCRIPTIONS: ".$sSubscriptions."</br>";
  28.  
  29. $res = add_user_meta($user->user_id, "wp__bbp_subscriptions", $sSubscriptions );
  30.  
  31. if($res == false){
  32. echo "META KEY WASN'T INSRETED!</br>";
  33. } else{
  34. echo "META KEY WAS INSERTED!</br>";
  35. }
  36.  
  37.  
  38. }
  39.  
  40. echo "SUBSCRIPTIONS FOR $i USERS WERE UPDATED FROM bb_favorites TO wp__bbp_subscriptions</br>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement