Skip to content

Instantly share code, notes, and snippets.

@mustafauysal
Created February 24, 2019 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mustafauysal/8a44bb55da476ff643ad9eb1005696e2 to your computer and use it in GitHub Desktop.
Save mustafauysal/8a44bb55da476ff643ad9eb1005696e2 to your computer and use it in GitHub Desktop.
<?php
// MASTER machine
$wpdb->add_database(array(
'host' => DB_HOST,
'user' => DB_USER,
'password' => DB_PASSWORD,
'name' => DB_NAME,
'write' => 1,
'read' => 0,
));
// REST READ-ONLY
$wpdb->add_database(array(
'host' => '192.168.1.9',
'user' => DB_USER,
'password' => DB_PASSWORD,
'name' => DB_NAME,
'write' => 0,
'read' => 1,
'dataset' => 'rest',
'timeout' => 0.4,
));
$wpdb->add_callback( 'my_db_callback' );
function my_db_callback( $query, $wpdb ) {
if ( defined( 'REST_REQUEST' ) && REST_REQUEST ){
return 'rest';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment