Skip to content

Instantly share code, notes, and snippets.

@sheabunge
Forked from chrisguitarguy/sunrise.php
Created November 7, 2012 20:01
Show Gist options
  • Save sheabunge/4034011 to your computer and use it in GitHub Desktop.
Save sheabunge/4034011 to your computer and use it in GitHub Desktop.
A `sunrise.php` drop in that (mostly) allows custom domains in WordPress multisite. Still needs some more work, but it gets the job done.
<?php
/**
* A sunrise.php drop in that allows you to use WordPress' built in `domain`
* and `path` settings for MultiSite blogs.
*
* Some limitations:
* - Using this with a MS install and paths (not subdomains) does some
* weird stuff when updating `siteurl` and `home` while updating domain.
* So you'll you'll have to update those separately. There are probably
* filters to fix this.
* - Each blog's `siteurl` should still include the path to WordPress if you
* have WP installed in a subdirectory. The site will still work without
* this, but going to wp-admin on that site will not.
* - You can only have a single domain (and it's matching (non-)www partner)
* per site. This probably isn't a big deal: it's supid to build the
* same site on more than one domain.
* - Non-apache folks may have a more difficult time with permalinks. I couldn't
* get rid of `index.php` using nginx -- WordPress kept adding it back in.
*
* @author Christopher Davis <chris [AT] classicalguitar.org>
* @license GPLv2
*/
if(defined('COOKIE_DOMAIN') || defined('SITECOOKIEPATH'))
{
die('"COOKIE_DOMAIN" or "SITECOOKIEPATH" is defined.');
}
$dm_domain = $_SERVER['HTTP_HOST'];
if(($nowww = preg_replace('/^www\./', '', $dm_domain)) != $dm_domain)
{
$where = $wpdb->prepare('domain IN (%s, %s)', $dm_domain, $nowww);
}
else
{
$where = $wpdb->prepare('domain = %s', $dm_domain);
}
if($_blog = $wpdb->get_row("SELECT * FROM {$wpdb->blogs} WHERE {$where} LIMIT 1"))
{
$current_blog = $_blog;
$blog_id = $_blog->blog_id;
$site_id = $current_blog->site_id;
$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);
define('COOKIE_DOMAIN', $_SERVER['HTTP_HOST']);
// WP uses $current_site->path to define this. We don't want that.
define('SITECOOKIEPATH', $current_blog->path);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment