public static function determine_protocol($server_global, $wp_is_ssl) { $forwarded_proto = UBUtil::array_fetch($server_global, 'HTTP_X_FORWARDED_PROTO'); $request_scheme = UBUtil::array_fetch($server_global, 'REQUEST_SCHEME'); $script_uri = UBUtil::array_fetch($server_global, 'SCRIPT_URI'); $script_uri_scheme = parse_url($script_uri, PHP_URL_SCHEME); $https = UBUtil::array_fetch($server_global, 'HTTPS', 'off'); // X-Forwarded-Proto should be respected first, as it is what the end // user will see (if Wordpress is behind a load balancer). if (UBHTTP::is_valid_protocol($forwarded_proto)) { return $forwarded_proto . '://'; } elseif (UBHTTP::is_valid_protocol($request_scheme)) { return $request_scheme . '://'; } elseif (UBHTTP::is_valid_protocol($script_uri_scheme)) { return $script_uri_scheme . '://'; } elseif ($wp_is_ssl || !is_null($https) && $https !== 'off') { return 'https://'; } else { return 'http://'; } }