Skip to content

Instantly share code, notes, and snippets.

@RealShermanB
Last active December 30, 2015 03:48
Show Gist options
  • Save RealShermanB/7771326 to your computer and use it in GitHub Desktop.
Save RealShermanB/7771326 to your computer and use it in GitHub Desktop.
Allow a single wordpress install to serve different content to different domains. This is version 0.0.0.0.1
<?php
/**
* This part resides in wp-config and is used to assign the domains
*
*/
if ( !defined('ABSPATH') )
define('ABSPATH', dirname(__FILE__) . '/');
function domain_theme($domain) {
define('WP_SITEURL', 'http://'.$domain);
define('WP_HOME', 'http://'.$domain);
}
$domain = $_SERVER['SERVER_NAME'];
$domain = str_replace('www.', '', $domain);
if (
$domain == 'domain1.com' ||
$domain == 'domain2.com' ||
$domain == 'domain3.com'
) {
domain_theme($domain);
}
/**
* This is a plugin used to create the domain specific content filter.
* Please note the version number before you judge.
*
* @package Author_Switcharoo
* @author Sherman Bausch <sbausch@nerdery.com>
* @version 0.2
*/
/*
Plugin Name: Author Switcharoo
Plugin URI: http://shermpress.com/specifically/wordpress/
Description: Filter global site content based on the site domain. There is some coding necessary: don't be afraid.
Author: Sherman Bausch <sbausch@nerdery.com>
Version: 0.2
Author URI: http://shermpress.com/
*/
function filter_content_by_site_author($query) {
if ( is_admin() || current_user_can("administer stuff") ) {
return;
}
$urls = array(
'domain1.com' => 3,
'domain2.com' => 2,
'domain3.com' => 1
);
$domain = $_SERVER['SERVER_NAME'];
if (!isset( $urls[$domain] )) {
return;
}
$tag_id = $urls[$domain];
// By Tag
$query->set('tag_id', $tag_id);
// By User
$query->set('author_id', wp_get_current_user()->id);
}
add_action('pre_get_posts', 'filter_content_by_site_author');
/**
* Switch to this
* http://codex.wordpress.org/Plugin_API/Filter_Reference/request
**/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment