-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fixes #32 and fixes #51 #59
Changes from 4 commits
3909209
52781b4
dc2bf99
b07bcb0
d46174a
686ff75
6760edd
40ddf34
de127bc
b31390d
0fbf184
59eb1bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,6 +290,8 @@ function register_mapped_filters() { | |
$GLOBALS['mercator_current_mapping'] = $mapping; | ||
add_filter( 'site_url', __NAMESPACE__ . '\\mangle_url', -10, 4 ); | ||
add_filter( 'home_url', __NAMESPACE__ . '\\mangle_url', -10, 4 ); | ||
add_filter( 'content_url', __NAMESPACE__ . '\\mangle_content_url', -10, 2 ); | ||
add_filter( 'lostpassword_url', __NAMESPACE__ . '\\mangle_content_url', -10, 2 ); | ||
|
||
// If on network site, also filter network urls | ||
if ( is_main_site() ) { | ||
|
@@ -324,3 +326,29 @@ function mangle_url( $url, $path, $orig_scheme, $site_id = 0 ) { | |
|
||
return $mangled; | ||
} | ||
|
||
/** | ||
* Mangle the content URL to give our mapped domain | ||
* | ||
* @param string $url The complete home URL including scheme and path. | ||
* @param string $path Path relative to the home URL. Blank string if no path is specified. | ||
* @return string Mangled Content URL | ||
*/ | ||
function mangle_content_url( $url, $path) { | ||
//get site ID for use with getting mapped domain name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comments need a space after the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I'd drop this comment and the next ( |
||
$site_id = get_current_blog_id(); | ||
//pull in site aliases | ||
$current_mapping = $GLOBALS['mercator_current_mapping']; | ||
//make sure the current domain is a mapped domain, else return the original url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Reword? Something like |
||
if ( empty( $current_mapping ) || $site_id !== (int) $current_mapping->get_site_id() ) { | ||
return $url; | ||
} | ||
|
||
// Replace the domain with mapped domain within the url | ||
$domain = parse_url( $url, PHP_URL_HOST ); | ||
$regex = '#^(\w+://)' . preg_quote( $domain, '#' ) . '#i'; | ||
$mangled = preg_replace( $regex, '${1}' . $current_mapping->get_domain(), $url ); | ||
|
||
//return filtered content url | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd drop this comment too, I think |
||
return $mangled; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
// Default mu-plugins directory if you haven't set it | ||
defined( 'WPMU_PLUGIN_DIR' ) or define( 'WPMU_PLUGIN_DIR', WP_CONTENT_DIR . '/mu-plugins' ); | ||
//uncomment the two lines below to disable SSO (single sign on) | ||
//add_filter( 'mercator.sso.enabled', '__return_false' ); | ||
//add_action( 'muplugins_loaded', 'Mercator\\SSO\\initialize_cookie_domain' ); | ||
require WPMU_PLUGIN_DIR . '/mercator/mercator.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs an extra space after
$path