Advertisement
verygoodplugins

Untitled

Apr 20th, 2021
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1.  
  2. function initialize_remote_db() {
  3.  
  4.     // Don't do it if we're already connected
  5.     if(get_home_url() == REMOTE_SITEURL) {
  6.         return;
  7.     }
  8.  
  9.     global $wpdb, $alt_db;
  10.  
  11.     // Swap
  12.     if( !empty( $alt_db ) ) {
  13.         $tempdb = $wpdb;
  14.         $wpdb = $alt_db;
  15.         $alt_db = $tempdb;
  16.     } else {
  17.         $alt_db = $wpdb;
  18.         $wpdb = new wpdb( REMOTE_DB_USER, REMOTE_DB_PASS, 'expressbuilders_s16', 'localhost' );
  19.         $wpdb->set_prefix('eb_');
  20.     }
  21.  
  22.     // Swap caches
  23.     global $wp_object_cache;
  24.     $wp_object_cache->multisite = true;
  25.     $wp_object_cache->blog_prefix = 'eb:';
  26.  
  27.     global $switched;
  28.     $switched = true;
  29.  
  30. }
  31.  
  32. /**
  33.  * Restore connection to original DB
  34.  *
  35.  * @return void
  36.  */
  37.  
  38. function restore_original_db() {
  39.  
  40.     // Don't do it if we're already restored
  41.     global $switched;
  42.  
  43.     if( $switched == false ) {
  44.         return;
  45.     }
  46.  
  47.     global $wpdb, $alt_db;
  48.     $tempdb = $wpdb;
  49.     $wpdb = $alt_db;
  50.     $alt_db = $tempdb;
  51.  
  52.     // Swap caches
  53.     global $wp_object_cache;
  54.     $wp_object_cache->multisite = false;
  55.     $wp_object_cache->blog_prefix = '';
  56.  
  57.     $switched = false;
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement