Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function initialize_remote_db() {
- // Don't do it if we're already connected
- if(get_home_url() == REMOTE_SITEURL) {
- return;
- }
- global $wpdb, $alt_db;
- // Swap
- if( !empty( $alt_db ) ) {
- $tempdb = $wpdb;
- $wpdb = $alt_db;
- $alt_db = $tempdb;
- } else {
- $alt_db = $wpdb;
- $wpdb = new wpdb( REMOTE_DB_USER, REMOTE_DB_PASS, 'expressbuilders_s16', 'localhost' );
- $wpdb->set_prefix('eb_');
- }
- // Swap caches
- global $wp_object_cache;
- $wp_object_cache->multisite = true;
- $wp_object_cache->blog_prefix = 'eb:';
- global $switched;
- $switched = true;
- }
- /**
- * Restore connection to original DB
- *
- * @return void
- */
- function restore_original_db() {
- // Don't do it if we're already restored
- global $switched;
- if( $switched == false ) {
- return;
- }
- global $wpdb, $alt_db;
- $tempdb = $wpdb;
- $wpdb = $alt_db;
- $alt_db = $tempdb;
- // Swap caches
- global $wp_object_cache;
- $wp_object_cache->multisite = false;
- $wp_object_cache->blog_prefix = '';
- $switched = false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement