+ $blog_data['scheme'] = $parsed_scheme;
+
+ if ( $is_main_site ) {
+ // On the network's main site, don't allow the domain or path to change.
+ $blog_data['domain'] = $details->domain;
+ $blog_data['path'] = $details->path;
+ } else {
+ // For any other site, the scheme, domain, and path can all be changed. We first
+ // need to ensure a scheme has been provided, otherwise fallback to the existing.
+ $new_url_scheme = parse_url( $blog_data['url'], PHP_URL_SCHEME );
+
+ if ( ! $new_url_scheme ) {
+ $blog_data['url'] = esc_url( $parsed_scheme . '://' . $blog_data['url'] );
+ }
+ $update_parsed_url = parse_url( $blog_data['url'] );
+
+ // If a path is not provided, use the default of `/`.
+ if ( ! isset( $update_parsed_url['path'] ) ) {
+ $update_parsed_url['path'] = '/';
+ }
+
+ $blog_data['scheme'] = $update_parsed_url['scheme'];
+ $blog_data['domain'] = $update_parsed_url['host'];
+ $blog_data['path'] = $update_parsed_url['path'];
+ }
+