-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from prisis/feature/new-Multisite-Directory-Re…
…solver-Manager Feature/new multisite directory resolver manager
- Loading branch information
Showing
10 changed files
with
511 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
namespace Gwa\Wordpress; | ||
|
||
/** | ||
* Wordpress Multisite fixer. | ||
* | ||
* @author Daniel Bannert <bannert@greatwhiteark.com> | ||
* @copyright 2015 Great White Ark | ||
* | ||
* @link http://www.greatwhiteark.com | ||
* | ||
* @license MIT | ||
*/ | ||
|
||
/** | ||
* AbstractResolver. | ||
* | ||
* @author Daniel Bannert | ||
*/ | ||
abstract class AbstractResolver | ||
{ | ||
/** | ||
* Folder path to wordpress, with trailing slash. | ||
* | ||
* @var string | ||
*/ | ||
protected $wpDirectoryPath = ''; | ||
|
||
/** | ||
* Wordpress folder name. | ||
* | ||
* @var string | ||
*/ | ||
protected $wpFolderName = ''; | ||
|
||
/** | ||
* MultisiteDirectoryResolver. | ||
* | ||
* @param string $wpdir | ||
*/ | ||
public function __construct($wpdir) | ||
{ | ||
$this->wpDirectoryPath = substr($wpdir, -1) === '/' ? $wpdir : $wpdir.'/'; | ||
$this->setWpFolderName(); | ||
} | ||
|
||
/** | ||
* Set the right links in Adminbar. | ||
* | ||
* @param string $path | ||
* @param string $scheme | ||
* | ||
* @return string | ||
*/ | ||
public function fixNetworkAdminUrlFilter($path = '', $scheme = 'admin') | ||
{ | ||
if (strpos($path, $this->wpDirectoryPath)) { | ||
return $path; | ||
} | ||
|
||
$wordpressUrl = [ | ||
'/(wp-admin)/', | ||
'/(wp-login\.php)/', | ||
'/(wp-activate\.php)/', | ||
'/(wp-signup\.php)/', | ||
]; | ||
|
||
$multiSiteUrl = [ | ||
$this->wpFolderName.'/wp-admin', | ||
$this->wpFolderName.'/wp-login.php', | ||
$this->wpFolderName.'/wp-activate.php', | ||
$this->wpFolderName.'/wp-signup.php', | ||
]; | ||
|
||
return preg_replace($wordpressUrl, $multiSiteUrl, $path, 1); | ||
} | ||
|
||
/** | ||
* Init all filter. | ||
*/ | ||
public function init() | ||
{ | ||
add_filter('network_admin_url', [$this, 'fixNetworkAdminUrlFilter'], 10, 2); | ||
|
||
add_filter('script_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); | ||
add_filter('style_loader_src', [$this, 'fixStyleScriptPathFilter'], 10, 2); | ||
} | ||
|
||
/** | ||
* Set wordpress folder name. | ||
* | ||
* @param string | ||
*/ | ||
protected function setWpFolderName() | ||
{ | ||
$dirs = explode('/', $this->wpDirectoryPath); | ||
|
||
$this->wpFolderName = $dirs[count($dirs) - 2]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
namespace Gwa\Wordpress\Contracts; | ||
|
||
/** | ||
* Wordpress Multisite fixer. | ||
* | ||
* @author Daniel Bannert <bannert@greatwhiteark.com> | ||
* @copyright 2015 Great White Ark | ||
* | ||
* @link http://www.greatwhiteark.com | ||
* | ||
* @license MIT | ||
*/ | ||
|
||
/** | ||
* MultisiteDirectoryResolver. | ||
* | ||
* @author Daniel Bannert | ||
*/ | ||
Interface MultisiteDirectoryResolver | ||
{ | ||
/** | ||
* Set the right links in Adminbar. | ||
* | ||
* @param string $path | ||
* @param string $scheme | ||
* | ||
* @return string | ||
*/ | ||
public function fixNetworkAdminUrlFilter($path = '', $scheme = 'admin'); | ||
|
||
/** | ||
* Set the right path for script and style loader. | ||
* | ||
* @param string $src | ||
* @param string $handle | ||
* | ||
* @return string | ||
*/ | ||
public function fixStyleScriptPathFilter($src, $handle); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
namespace Gwa\Wordpress; | ||
|
||
/** | ||
* Wordpress Multisite fixer. | ||
* | ||
* @author Daniel Bannert <bannert@greatwhiteark.com> | ||
* @copyright 2015 Great White Ark | ||
* | ||
* @link http://www.greatwhiteark.com | ||
* | ||
* @license MIT | ||
*/ | ||
|
||
/** | ||
* MultisiteResolverManager. | ||
* | ||
* @author Daniel Bannert | ||
*/ | ||
class MultisiteResolverManager | ||
{ | ||
const TYPE_SUBDOMAIN = '\Gwa\Wordpress\MultisiteSubDomainResolver'; | ||
const TYPE_FOLDER = '\Gwa\Wordpress\MultisiteDirectoryResolver'; | ||
|
||
/** | ||
* Resolver Handler | ||
* | ||
* @var \Gwa\Wordpress\Contracts\MultisiteDirectoryResolver | ||
*/ | ||
protected $handler; | ||
|
||
/** | ||
* MultisiteResolverManager. | ||
* | ||
* @param string $wpdir | ||
* @param string $multisiteDomainType | ||
*/ | ||
public function __construct($wpdir, $multisiteDomainType) { | ||
if (!is_string($wpdir) || $wpdir === '' || $wpdir === '/') { | ||
throw new \Exception('Please set the relative path to your Wordpress install folder.'); | ||
} | ||
|
||
$this->handler = new $multisiteDomainType($wpdir); | ||
} | ||
|
||
/** | ||
* Get current Handler | ||
* | ||
* @return \Gwa\Wordpress\Contracts\MultisiteDirectoryResolver | ||
*/ | ||
public function getHandler() | ||
{ | ||
return $this->handler; | ||
} | ||
|
||
/** | ||
* Init all filter. | ||
*/ | ||
public function init() | ||
{ | ||
$this->handler->init(); | ||
} | ||
} |
Oops, something went wrong.