Permalink
Browse files

Initial checkin

  • Loading branch information...
0 parents commit 202efadc5fcfaea0a6cf6c745e1f59ae2d51661f @nathancarnes committed Oct 27, 2011
Showing with 154 additions and 0 deletions.
  1. +105 −0 MultiDomain.php
  2. +49 −0 config.php
@@ -0,0 +1,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);
+?>
@@ -0,0 +1,49 @@
+<?php
+/*
+* MultiDomains Configuration
+*
+* Configuration is handled via the $domains array. Examples are below.
+* Note: if a no configuration is given for a domain, WordPress defaults will be used.
+* Typically you won't need to configure your primary domain, only additional domains.
+*
+* Arguments:
+* domain: Domain name or subdomain to match (required)
+* siteurl: Site URL (required)
+* home: Home URL (required; usually the same as siteurl)
+* blogname: Override default site name (optional)
+* blogdescription: Override default site description (optional)
+* template: Override default site template (optional)
+*/
+
+/* Minimal Example */
+// $domains = array(
+// array(
+// 'domain' => 'myalternatedomain.com',
+// 'siteurl' => 'http://myalternatedomain.com',
+// 'home' => 'http://myalternatedomain.com'
+// )
+// );
+
+/* More Complex Example */
+// $domains = array(
+// array(
+// 'domain' => 'example1.com',
+// 'siteurl' => 'http://example1.com',
+// 'home' => 'http://example1.com'
+// ),
+// array(
+// 'domain' => 'example2.com',
+// 'siteurl' => 'http://example2.com',
+// 'home' => 'http://example2.com',
+// 'blogname' => 'Example 2'
+// ),
+// array(
+// 'domain' => 'example3.com',
+// 'siteurl' => 'http://example3.com',
+// 'home' => 'http://example3.com',
+// 'template' => 'twentyten',
+// 'blogname' => 'I have a different name...',
+// 'blogdescription' => '..and description'
+// )
+// );
+?>

0 comments on commit 202efad

Please sign in to comment.