Skip to content

Commit

Permalink
Single-site support.
Browse files Browse the repository at this point in the history
Bump to 4.0.0.
  • Loading branch information
JJJ committed Mar 6, 2017
1 parent af38226 commit 21ec8b2
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 7 deletions.
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: johnjamesjacoby, stuttter
Tags: blog, site, meta, multisite, alias, domain, mapping
Requires at least: 4.5
Tested up to: 4.8
Stable tag: 3.0.0
Stable tag: 4.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9Q4F4EL5YJ62J
Expand Down Expand Up @@ -74,6 +74,9 @@ http:https://github.com/stuttter/wp-site-aliases/

== Changelog ==

= [4.0.0] - 2017-03-17 =
* Single-site support

= [3.0.0] - 2016-12-06 =
* Add support for aliases to redirect vs. mask

Expand Down
8 changes: 8 additions & 0 deletions wp-site-aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function _wp_site_aliases() {
require_once $plugin_path . 'includes/classes/class-wp-site-aliases-db-tables.php';

// Required Files
require_once $plugin_path . 'includes/functions/abstraction.php';
require_once $plugin_path . 'includes/functions/admin.php';
require_once $plugin_path . 'includes/functions/assets.php';
require_once $plugin_path . 'includes/functions/capabilities.php';
Expand All @@ -43,6 +44,13 @@ function _wp_site_aliases() {
require_once $plugin_path . 'includes/functions/metadata.php';
require_once $plugin_path . 'includes/functions/hooks.php';

// Single-site shims
if ( ! is_multisite() ) {
require_once ABSPATH . WPINC . '/ms-blogs.php';
require_once ABSPATH . WPINC . '/class-wp-site.php';
require_once ABSPATH . WPINC . '/class-wp-network.php';
}

// Register database table
if ( empty( $GLOBALS['wpdb']->blog_aliases ) ) {
$GLOBALS['wpdb']->blog_aliases = "{$GLOBALS['wpdb']->base_prefix}blog_aliases";
Expand Down
53 changes: 53 additions & 0 deletions wp-site-aliases/includes/functions/abstraction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* Site Aliases Abstractions
*
* @package Plugins/Site/Aliases/Abstractions
*/

// Exit if accessed directly
defined( 'ABSPATH' ) || exit;

/**
* Single-site abstractions of get_blog_details()
*
* @since 4.0.0
*
* @param mixed $fields
* @param bool $get_all
*
* @return \WP_Site
*/
function wp_site_aliases_get_site_details( $fields = null, $get_all = true ) {

// Use regular multisite function
if ( is_multisite() ) {
$site = get_blog_details( $fields, $get_all );

// Shim site details into a proper site object
} else {
$url = parse_url( home_url( '/' ) );
$site = new WP_Site( (object) array(
'id' => get_current_blog_id(),
'network_id' => get_current_network_id(),
'domain' => $url['host'],
'path' => $url['path']
) );
}

return $site;
}

/**
* Single-site abstraction to get $current_blog global
*
* @since 4.0.0
*
* @return WP_Site
*/
function wp_site_aliases_get_current_site() {
return is_multisite()
? $GLOBALS['current_blog']
: wp_site_aliases_get_site_details();
}
8 changes: 4 additions & 4 deletions wp-site-aliases/includes/functions/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function wp_site_aliases_get_site_id() {
}

// Get the blog details
$details = get_blog_details( $site_id );
$details = wp_site_aliases_get_site_details( $site_id );

// No blog details
if ( empty( $details ) ) {
Expand Down Expand Up @@ -198,7 +198,7 @@ function wp_site_aliases_check_domain_alias( $site, $domain ) {
}

// Fetch the actual data for the site
$aliased_site = get_blog_details( $alias->site_id );
$aliased_site = wp_site_aliases_get_site_details( $alias->site_id );
if ( empty( $aliased_site ) ) {
return $site;
}
Expand Down Expand Up @@ -242,7 +242,7 @@ function wp_site_aliases_clear_aliases_on_delete( $site_id = 0 ) {
function wp_site_aliases_register_url_filters() {

// Look for aliases
$current_site = $GLOBALS['current_blog'];
$current_site = wp_site_aliases_get_current_site();
$real_domain = $current_site->domain;
$domain = $_SERVER['HTTP_HOST'];

Expand Down Expand Up @@ -372,7 +372,7 @@ function wp_site_aliases_check_aliases_for_site( $site, $domain, $path, $path_se
}

// Set site & network
$site = get_blog_details( $alias->site_id );
$site = wp_site_aliases_get_site_details( $alias->site_id );
$current_site = get_network( $site->site_id );

// We found a network, now check for the site. Replace mapped domain with
Expand Down
4 changes: 2 additions & 2 deletions wp-site-aliases/includes/functions/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
add_action( 'delete_blog', 'wp_site_aliases_clear_aliases_on_delete' );

// URL Filters
add_action( 'muplugins_loaded', 'wp_site_aliases_register_url_filters', -10 );
add_action( 'plugins_loaded', 'wp_site_aliases_register_url_filters', -10 );

// Columns
add_action( 'manage_sites_custom_column', 'wp_site_aliases_output_site_list_column', 10, 2 );
add_filter( 'wpmu_blogs_columns', 'wp_site_aliases_add_site_list_column' );
add_filter( 'wpmu_blogs_columns', 'wp_site_aliases_add_site_list_column' );

// Navigation
add_filter( 'network_edit_site_nav_links', 'wp_site_aliases_add_site_tab' );
Expand Down

0 comments on commit 21ec8b2

Please sign in to comment.