Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
BuddyPress HyperDB example
<?php
$wpdb->add_database( array(
'host' => 'global.db.example.com',
'user' => 'globaluser',
'password' => 'globalpassword',
'name' => 'globaldb',
) );
$wpdb->add_database( array(
'host' => 'bp.db.example.com',
'user' => 'bpdbuser',
'password' => 'bpdbpassword',
'name' => 'bpdb',
'dataset' => 'bp',
) );
$wpdb->add_callback( 'my_db_callback' );
// depends on your bp prefix bp_core_get_table_prefix() probably not working here
function my_db_callback( $query, $wpdb ) {
if ( preg_match("/bp_/", $wpdb->table) ) {
return 'bp';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment