Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Added action inside redirect method to allow developers to create the…
Browse files Browse the repository at this point in the history
…ir own access logic. #2
  • Loading branch information
straube committed Jul 28, 2016
1 parent 2ad1e9b commit 7d0a2c1
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,37 @@ WordPress installation since 3.0, you can find more info here: https://codex.wor

**There is a way to add domain based logic to my themes?**

Absolutely. You can use the `MULTPLE_DOMAIN_DOMAIN` constant to get the current domain. Just notice that since this
value is checked against plugin settings, it may not reflect the actual domain in `HTTP_HOST` element from `$_SERVER` or
user's browser. It also may include the host port when it's different than 80 (default HTTP port) or 443 (default HTTPS
port).
Absolutely. You can use the `MULTPLE_DOMAIN_DOMAIN` and `MULTPLE_DOMAIN_ORIGINAL_DOMAIN` constants to get the current
and original domains. Just notice that since the value of the first one is checked against plugin settings, it may not
reflect the actual domain in `HTTP_HOST` element from `$_SERVER` or user's browser. They also may include the host port
when it's different than 80 (default HTTP port) or 443 (default HTTPS port).

**Can I create a custom access restriction logic for each domain?**

Yes. You can use the `multiple_domain_redirect` action to do that. For example:

function my_custom_redirect($domain)
{
// Do nothing if the request is using the original domain.
if ($domain === MULTPLE_DOMAIN_ORIGINAL_DOMAIN) {
return;
}
// If the URI doesn't start with /cool/path, redirect the user to the original domain.
if (!empty($_SERVER['REQUEST_URI']) && !preg_match('/^\/cool\/path/i', $_SERVER['REQUEST_URI'])) {
wp_redirect('http://' . MULTPLE_DOMAIN_ORIGINAL_DOMAIN . '/');
exit;
}
}

add_action('multiple_domain_redirect', 'my_custom_redirect');

## Changelog

### 0.3

* Fixed bug when removing the port from current domain.
* Added `MULTPLE_DOMAIN_ORIGINAL_DOMAIN` constant to hold the original WP home domain.
* Allowing developers to create custom URL restriction logic through `multiple_domain_redirect` action.
* ...

### 0.2
Expand Down
6 changes: 6 additions & 0 deletions multiple-domain/multiple-domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ public function getOriginalDomain()
*/
public function redirect()
{

/*
* Allow developers to create their own logic for redirection.
*/
do_action('multiple_domain_redirect', $this->domain);

if (!empty($this->domains[$this->domain])) {
$base = $this->domains[$this->domain];
if (!empty($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], $base) !== 0) {
Expand Down
19 changes: 19 additions & 0 deletions multiple-domain/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ value is checked against plugin settings, it may not reflect the actual domain i
user's browser. It also may include the host port when it's different than 80 (default HTTP port) or 443 (default HTTPS
port).

= Can I create a custom access restriction logic for each domain? =

Yes. You can use the `multiple_domain_redirect` action to do that. For example:

function my_custom_redirect($domain)
{
// Do nothing if the request is using the original domain.
if ($domain === MULTPLE_DOMAIN_ORIGINAL_DOMAIN) {
return;
}
// If the URI doesn't start with /cool/path, redirect the user to the original domain.
if (!empty($_SERVER['REQUEST_URI']) && !preg_match('/^\/cool\/path/i', $_SERVER['REQUEST_URI'])) {
wp_redirect('http://' . MULTPLE_DOMAIN_ORIGINAL_DOMAIN . '/');
exit;
}
}

add_action('multiple_domain_redirect', 'my_custom_redirect');

== Screenshots ==

== Changelog ==
Expand Down

0 comments on commit 7d0a2c1

Please sign in to comment.