Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress network sunrise.php for multiple environments with a single database
<?php
// Check the current host or server name
if (isset($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
} elseif (isset($_SERVER['SERVER_NAME'])) {
$host = $_SERVER['SERVER_NAME'];
}
// Switch the host to the desired domain
if ( DOMAIN_CURRENT_SITE == $host && WP_LOCAL_DEV ) {
$host = 'staging.example.com';
}
if (is_subdomain_install()) {
$sql = $wpdb -> prepare("SELECT * FROM {$wpdb->blogs} WHERE domain = %s LIMIT 1", $host);
} else {
// Get the path from the URl
$path = explode('/', ltrim($_SERVER['REQUEST_URI'], '/'));
if (count($path))
$path = '/' . $path[0];
else
$path = '/';
$sql = $wpdb -> prepare("SELECT * FROM {$wpdb->blogs} WHERE path in ('{$path}', '{$path}/') AND domain = %s LIMIT 1", $host, $path);
}
if ($_blog = $wpdb -> get_row($sql)) {
$current_blog = $_blog;
$blog_id = $_blog -> blog_id;
$site_id = $current_blog -> site_id;
// set current site
$current_site = $wpdb -> get_row($wpdb -> prepare("SELECT * from {$wpdb->site} WHERE id = %d", $site_id));
$current_site -> blog_id = $blog_id;
$current_site = get_current_site_name($current_site);
}
@developdaly

This comment has been minimized.

Copy link
Owner Author

developdaly commented Dec 3, 2012

Credit for this goes to chrisguitarguy for his answer on Stack Exchange.

@royduin

This comment has been minimized.

Copy link

royduin commented Jan 9, 2015

get_current_site_name is deprecated since Wordpress 3.9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.