Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Last active February 3, 2020 10:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafauysal/06bae4b8a501735393f2e60c6c33d51c to your computer and use it in GitHub Desktop.
Save mustafauysal/06bae4b8a501735393f2e60c6c33d51c to your computer and use it in GitHub Desktop.
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