Quantcast
Channel: WordPress.org Forums » [WordPress MU Domain Mapping] Support
Viewing all articles
Browse latest Browse all 3502

Luis Rodrigues on "[Plugin: WordPress MU Domain Mapping] Broken URLs for JavaScript and CSS assets inside mu-plugins"

$
0
0

Hi guys,

I've bumped into the same broken URL issue being discussed in this thread: https://wordpress.org/support/topic/wordpress-mu-domain-mapping-and-mu-plugins-wrong-urls

Surprised to find it's a 3-year-old bug, one for which the OP even provided a fix (however rudimentary). Unless I'm missing something here, the reasons given for not applying the fix could have been quickly resolved by replacing the hardcoded path strings with the PLUGINDIR and MUPLUGINDIR constants, like so:


function domain_mapping_plugins_uri( $full_url, $path=NULL, $plugin=NULL ) {
if ( false !== strpos($full_url, MUPLUGINDIR ) )
$mapped_url = get_option( 'siteurl' ) . substr( $full_url, stripos( $full_url, MUPLUGINDIR ) - 1 );
else
$mapped_url = get_option( 'siteurl' ) . substr( $full_url, stripos( $full_url, PLUGINDIR ) - 1 );
return $mapped_url;
}

(I also tried the domain_mapping_themes_uri() function used to rewrite theme asset URLs and found that it works fine with plugins and mu-plugins alike, at least on a standard multisite configuration.)

Anyhoo, until an official fix is available, I have successfully worked around the issue with the plugins_url hook using the (slightly rewritten) code below:


function fixed_domain_mapping_plugins_uri( $full_url ) {
$plugin_dir = stripos( $full_url, MUPLUGINDIR ) === false ? PLUGINDIR : MUPLUGINDIR;
return get_option( 'siteurl' ) . substr( $full_url, stripos( $full_url, $plugin_dir ) - 1 );
}

function fix_domain_mapping_mu() {
remove_filter( 'plugins_url', 'domain_mapping_plugins_uri', 1 );
add_filter( 'plugins_url', 'fixed_domain_mapping_plugins_uri', 1 );
}

if ( defined( 'DOMAIN_MAPPING' ) && function_exists( 'fixed_domain_mapping_plugins_uri' ) ) {
add_action( 'plugins_loaded', 'fix_domain_mapping_mu' );
}

Hope this helps.

https://wordpress.org/plugins/wordpress-mu-domain-mapping/


Viewing all articles
Browse latest Browse all 3502

Trending Articles