Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function switch_to_network_blog($network_prefix, $blog_id)
- {
- global $wpdb, $wp_object_cache, $last_network_prefix;
- //save prefix for restoring
- $last_network_prefix = $wpdb->base_prefix;
- if($network_prefix == $last_network_prefix)
- {
- //if on the same network, use wp functionality
- switch_to_blog($blog_id);
- }
- else
- {
- //Change prefix
- $wpdb->base_prefix = $network_prefix;
- $wpdb->prefix = $wpdb->get_blog_prefix();
- //Switch over
- switch_to_blog($blog_id);
- //Clear cache
- $wp_object_cache->flush();
- }
- }
- function restore_current_network_blog()
- {
- global $wpdb, $wp_object_cache, $last_network_prefix;
- if($last_network_prefix == $wpdb->base_prefix)
- {
- //if on the same network, use wp functionality
- restore_current_blog();
- }
- else
- {
- //Change prefix
- $wpdb->base_prefix = $last_network_prefix;
- $wpdb->prefix = $wpdb->get_blog_prefix();
- //Restore
- restore_current_blog();
- //Clear cache
- $wp_object_cache->flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement