Skip to content

Commit

Permalink
Merge pull request #7 from boxuk/fix-main-subdomain-issue
Browse files Browse the repository at this point in the history
[BUG] Fix subdomain install adding extra site.
  • Loading branch information
Ian Jenkins authored Apr 23, 2021
2 parents fa4ebbb + 8598df4 commit a22122c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
34 changes: 34 additions & 0 deletions features/network-sites.feature
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,37 @@ Feature: Network Sites Region
"""
en_GB
"""

Scenario: Impose Network Sites with subdomains with main site without a subdomain
Given a WP multisite subdomain install
And a network-state.yml file:
"""
state: network
sites:
:
title: Main site
description: This is the main site with no subdomain required
active_theme: p2
active_plugins:
- akismet/akismet.php
timezone_string: Europe/London
WPLANG: en_GB
sub:
title: Sub site
description: This is the sub site with a subdomain of 'sub' required
active_theme: p2
active_plugins:
- akismet/akismet.php
timezone_string: Europe/London
WPLANG: en_GB
"""

When I run `wp dictator impose network-state.yml`
Then STDOUT should not be empty

When I run `wp site list --field=url`
Then STDOUT should be:
"""
http://example.com/
http://sub.example.com/
"""
11 changes: 9 additions & 2 deletions php/regions/class-network-sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public function get_differences() {
* @return true|WP_Error
*/
public function impose( $key, $value ) {
if ( $key === '' ) {
$key = get_current_site()->domain;
}

$site = $this->get_site( $key );
if ( ! $site ) {
Expand Down Expand Up @@ -346,8 +349,12 @@ protected function create_site( $key, $value ) {
}

if ( is_subdomain_install() ) {
$path = '/';
$newdomain = $base . '.' . preg_replace( '|^www\.|', '', $network->domain );
$path = '/';
$prefix = '';
if ( $base !== '' ) {
$prefix = $base . '.';
}
$newdomain = $prefix . preg_replace( '|^www\.|', '', $network->domain );
} else {
$newdomain = $network->domain;
$path = '/' . trim( $base, '/' ) . '/';
Expand Down

0 comments on commit a22122c

Please sign in to comment.