Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

WP Hyper Users Table Fix

By: a guest on Dec 29th, 2011  |  syntax: PHP  |  size: 1.10 KB  |  views: 143  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. add_filter( 'query', 'mycustom_query_alter' );
  2. function mycustom_query_alter( $query ) {
  3.         global $wpdb;
  4.         // Try to go into HyperDB settings to find DB name of shared users DB
  5.         // The dataset is named "users"
  6.         if (!empty($wpdb->hyper_servers['users'])) {
  7.                 if (!empty($wpdb->hyper_servers['users']['read'][1][0]['name'])) {
  8.                         $users_db = $wpdb->hyper_servers['users']['read'][1][0]['name'];
  9.                 }  
  10.                 else {
  11.                         // We didn't find a users table in HyperDB, so we'll default to a standard one
  12.                         $users_db = 'wp_users';
  13.                 }  
  14.  
  15.                 // If the query references both $wpdb->users and $wpdb->usermeta tables, prefix the users table with correct database name
  16.                 if (FALSE !== strpos($query, $wpdb->users) &&
  17.                         FALSE !== strpos($query, $wpdb->usermeta)) {
  18.                         $query = str_replace($wpdb->users, $users_db . '.' . $wpdb->users, $query);
  19.                 }  
  20.         }  
  21.         return $query;
  22. }