-
Notifications
You must be signed in to change notification settings - Fork 1
/
MultiDomain.php
105 lines (83 loc) · 2.53 KB
/
MultiDomain.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
/*
Plugin Name: MultiDomain
Plugin URI: http://github.com/nathancarnes/MultiDomain
Description: Allows WordPress to be used with mirrored domains, allowing title, description, and theme switching based on domain. Also provides conditional shortags. Inspired by Domain Mirror (http://mcaleavy.org/code/domain-mirror/).
Author: Nathan Carnes
Version: 1.0
Author URI: http://carnesmedia.com
*/
class MultiDomain{
static $instance;
public $domains, $domain, $conditional_fired;
function __construct($config) {
self::$instance = $this;
$this->domains = $config;
$this->get_domain();
// Register Filters
if($this->domain){
$properties = array('blogname', 'siteurl', 'home', 'blogdescription', 'template');
foreach($properties as $property) {
if($this->domain[$property]){
add_filter("option_$property", array( $this, $property ), 1);
if($property == 'template') {
add_filter("template", array( $this, "template" ), 1);
add_filter("option_stylesheet", array( $this, "template" ), 1);
}
}
}
}
// Register Shortcodes
add_shortcode('MultiDomain_if', array( $this, 'if_domain' ) );
add_shortcode('MultiDomain_else', array( $this, 'else_domain' ) );
add_shortcode('MultiDomain_default', array( $this, 'else_domain' ) );
}
function current_domain() {
return $_SERVER[SERVER_NAME];
}
function get_domain() {
$domains = $this->domains;
if($domains) {
foreach($domains as $domain) {
if($this->current_domain() == $domain[domain]){
$this->domain = $domain;
}
}
}
}
/* Set Site Properties */
function blogname() {
return $this->domain[blogname];
}
function siteurl() {
return $this->domain[siteurl];
}
function home() {
return $this->domain[home];
}
function blogdescription() {
return $this->domain[blogdescription];
}
function stylesheet() {
return $this->domain[stylesheet];
}
function template() {
return $this->domain[template];
}
/* Conditional Shortcodes */
function if_domain( $attributes, $content = null ) {
extract( shortcode_atts( array( 'domain' => null ), $attributes ) );
if( $domain == $this->domain[domain] ) {
$this->conditional_fired = true;
return do_shortcode( $content );
}
}
function else_domain( $attributes, $content = null ) {
if( !$this->conditional_fired ) {
return do_shortcode( $content );
}
}
}
include_once('config.php');
new MultiDomain($domains);
?>