Guest User

s2M bbPress fix

a guest
Jun 3rd, 2010
897
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Show Database Errors
  3. // Comment this line out when going live :)
  4. $wpdb->show_errors();
  5.  
  6.  
  7. // 99 times out of 100 this is overkill
  8. // I'm just being on the safe side
  9. //
  10. // It checks what the current user ID is
  11. if ( !$user_id ) {
  12.     $current_user = wp_get_current_user();
  13.     $user_id = $current_user->ID;
  14. } else {
  15.     $user_id = (int) $user_id;
  16. }
  17.  
  18. // Connects to the database
  19. // Retrieves the value for this user for wp_capabilities
  20. $user_cap = $wpdb->get_row( "SELECT meta_value FROM wp_usermeta WHERE user_id=$user_id AND meta_key='wp_capabilities' LIMIT 1" );
  21.  
  22.  
  23.     // Checks to see if the user already has a bb_capabilities
  24.     // If it does we'll overwrite it
  25.     // If it doesn't we'll add a new one.
  26.    
  27.     $user_cap_in_bb_meta = $wpdb->get_row( "SELECT meta_value FROM bb_usermeta WHERE user_id=$user_id AND meta_key='bb_capabilities' LIMIT 1" );   
  28.    
  29.     if ($user_cap_in_bb_meta)
  30.     {
  31.         // update bbPress database
  32.         $wpdb->query("UPDATE bb_usermeta SET meta_value='". $user_cap->meta_value ."' WHERE user_id=". $user_id ." AND meta_key= 'bb_capabilities' ");     
  33.     } else {
  34.         // Add a new row to the bbPress database
  35.         $wpdb->query("INSERT INTO bb_usermeta (user_id, meta_key, meta_value) VALUES (". $user_id .", bb_capabilities, '". $user_cap->meta_value ."') ");  
  36.     }
  37.    
  38.  
  39.  
  40. // Print all Database errors
  41. // Comment this line out when going live :)
  42. $wpdb->print_error();
  43.  
  44. // Hide Database Errors
  45. // Comment this line out when going live :)
  46. $wpdb->hide_errors();
RAW Paste Data