Last active
February 3, 2020 10:08
-
-
Save mustafauysal/06bae4b8a501735393f2e60c6c33d51c to your computer and use it in GitHub Desktop.
BuddyPress HyperDB example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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