If you DON’T have access to the Networks admin panel, drop the following into a file in your mu-plugins
directory to bypass the main site and get to the network admin on the broken network:
add_filter( 'network_site_url', 'fix_network_site_url', 10, 3);
add_filter( 'redirect_network_admin_request', 'fix_network_admin_redirect' );
/**
* Rewrite Network Admin URL when there is not a root site
*/
if( ! function_exists( 'fix_network_site_url' ) ) {
function fix_network_site_url( $url, $path, $scheme ) {
global $current_site, $current_blog, $wpdb;
if( $current_blog->path != $current_site->path ) {
if( ! $current_site->blog_id ) {
$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM " . $wpdb->blogs . " WHERE domain = %s AND archived = '0' AND spam = 0 AND deleted = 0 ORDER BY registered LIMIT 1", $current_site->domain ) );
}
if( ! $current_site->blog_id ) {
wp_die( __( 'Unable to locate a valid site on this network.', 'njsl-networks' ), __( 'No Valid Site Found', 'njsl-networks' ) );
}
$blog = get_blog_details( $current_site->blog_id, false );
$url = str_replace( $current_site->domain . $current_site->path, $current_site->domain . $blog->path, $url );
}
return $url;
}
}
/**
* Rewrite Network Admin redirect when there is not a root site
*/
if( ! function_exists( 'fix_network_admin_redirect' ) ) {
function fix_network_admin_redirect( $do_redirect ) {
global $current_site, $current_blog, $wpdb;
if( $do_redirect ) {
if( ! $current_site->blog_id ) {
$current_site->blog_id = $wpdb->get_var( $wpdb->prepare( "SELECT blog_id FROM " . $wpdb->blogs . " WHERE domain = %s AND archived = '0' AND spam = 0 AND deleted = 0 ORDER BY registered LIMIT 1", $current_site->domain ) );
}
if( ! $current_site->blog_id ) {
wp_die( __( 'Unable to locate a valid site on this network.', 'njsl-networks' ), __( 'No Valid Site Found', 'njsl-networks' ) );
}
$blog = get_blog_details( $current_site->blog_id, false );
return ( $current_site->domain != $current_blog->domain ) || ( $current_blog->path != $blog->path );
}
return $do_redirect;
}
}