Skip to content

Instantly share code, notes, and snippets.

@abackstrom
Created September 28, 2011 01:49
Show Gist options
  • Save abackstrom/1246788 to your computer and use it in GitHub Desktop.
Save abackstrom/1246788 to your computer and use it in GitHub Desktop.
wordpress-mu-domain-mapping patches
Index: domain_mapping.php
===================================================================
--- domain_mapping.php (revision 9545)
+++ domain_mapping.php (revision 9553)
@@ -515,27 +515,37 @@
}
-function domain_mapping_siteurl( $setting ) {
- global $wpdb, $current_blog;
+function domain_mapping_siteurl( $setting, $blog_id = 0 ) {
+ global $wpdb, $current_blog, $switched;
// To reduce the number of database queries, save the results the first time we encounter each blog ID.
static $return_url = array();
+ if( $blog_id == 0 ) {
+ $blog_id = $current_blog->blog_id;
+ }
+
$wpdb->dmtable = $wpdb->base_prefix . 'domain_mapping';
- if ( !isset( $return_url[ $wpdb->blogid ] ) ) {
+ if ( !isset( $return_url[ $blog_id ] ) ) {
$s = $wpdb->suppress_errors();
- if ( get_site_option( 'dm_no_primary_domain' ) == 1 ) {
- $domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$wpdb->blogid}' AND domain = '" . $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] ) . "' LIMIT 1" );
+ if ( get_site_option( $blog_id, 'dm_no_primary_domain' ) == 1 ) {
+ if ( $switched === false ) {
+ // Only filter using HTTP_HOST if we haven't done switch_to_blog()
+ $domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$blog_id}' AND domain = '" . $wpdb->escape( $_SERVER[ 'HTTP_HOST' ] ) . "' LIMIT 1" );
+ } else {
+ $domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$blog_id}' LIMIT 1" );
+ }
+
if ( null == $domain ) {
- $return_url[ $wpdb->blogid ] = untrailingslashit( get_original_url( "siteurl" ) );
- return $return_url[ $wpdb->blogid ];
+ $return_url[ $blog_id ] = untrailingslashit( get_original_url( "siteurl", $blog_id ) );
+ return $return_url[ $blog_id ];
}
} else {
// get primary domain, if we don't have one then return original url.
- $domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$wpdb->blogid}' AND active = 1 LIMIT 1" );
+ $domain = $wpdb->get_var( "SELECT domain FROM {$wpdb->dmtable} WHERE blog_id = '{$blog_id}' AND active = 1 LIMIT 1" );
if ( null == $domain ) {
- $return_url[ $wpdb->blogid ] = untrailingslashit( get_original_url( "siteurl" ) );
- return $return_url[ $wpdb->blogid ];
+ $return_url[ $blog_id ] = untrailingslashit( get_original_url( "siteurl", $blog_id ) );
+ return $return_url[ $blog_id ];
}
}
@@ -546,11 +556,11 @@
$protocol = ( 'on' == strtolower( $_SERVER[ 'HTTPS' ] ) ) ? 'https://' : 'http://';
if ( $domain ) {
- $return_url[ $wpdb->blogid ] = untrailingslashit( $protocol . $domain );
- $setting = $return_url[ $wpdb->blogid ];
- } else {
- $return_url[ $wpdb->blogid ] = false;
- }
- } elseif ( $return_url[ $wpdb->blogid ] !== FALSE) {
- $setting = $return_url[ $wpdb->blogid ];
+ $return_url[ $blog_id ] = untrailingslashit( $protocol . $domain );
+ $setting = $return_url[ $blog_id ];
+ } else {
+ $return_url[ $blog_id ] = false;
+ }
+ } elseif ( $return_url[ $blog_id ] !== FALSE) {
+ $setting = $return_url[ $blog_id ];
}
Index: domain_mapping.php
===================================================================
--- domain_mapping.php (revision 9553)
+++ domain_mapping.php (revision 9554)
@@ -660,5 +660,9 @@
// fixes the plugins_url
function domain_mapping_plugins_uri( $full_url, $path=NULL, $plugin=NULL ) {
- return get_option( 'siteurl' ) . substr( $full_url, stripos( $full_url, PLUGINDIR ) - 1 );
+ if( false === ( $pos = stripos( $full_url, PLUGINDIR ) ) ) {
+ $pos = stripos( $full_url, MUPLUGINDIR );
+ }
+
+ return get_option( 'siteurl' ) . substr( $full_url, $pos - 1 );
}
@@ -668,5 +672,5 @@
if ( defined( 'DOMAIN_MAPPING' ) ) {
- add_filter( 'plugins_url', 'domain_mapping_plugins_uri', 1 );
+ add_filter( 'plugins_url', 'domain_mapping_plugins_uri', 1, 3 );
add_filter( 'theme_root_uri', 'domain_mapping_themes_uri', 1 );
add_filter( 'pre_option_siteurl', 'domain_mapping_siteurl' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment