{"id":18996616,"date":"2026-08-18T17:30:13","date_gmt":"2026-08-18T17:30:13","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/fatal-error-wp_parse_url-called-before-wordpress-loads-its-functions\/"},"modified":"2026-08-18T17:30:13","modified_gmt":"2026-08-18T17:30:13","slug":"fatal-error-wp_parse_url-called-before-wordpress-loads-its-functions","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/fatal-error-wp_parse_url-called-before-wordpress-loads-its-functions\/","title":{"rendered":"Fatal error: wp_parse_url() called before WordPress loads its functions"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Hi,<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">BerqWP 4.1.12 can trigger a reproducible fatal error because its advanced-cache drop-in calls a WordPress function before WordPress has loaded the file that defines it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Environment tested:<\/p>\n\n\n\n<ul>\n<li>BerqWP 4.1.12<\/li>\n\n\n\n<li>WordPress 7.0.4<\/li>\n\n\n\n<li>PHP 8.3<\/li>\n\n\n\n<li>Reverse-proxy\/origin setup<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Cause:<br \/>wp-settings.php loads wp-content\/advanced-cache.php very early. The BerqWP drop-in includes inc\/common-functions.php and calls bwp_serve_advanced_cache(). In common-functions.php, the non-HTTPS branch calls:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">wp_parse_url(get_option(&#8216;home&#8217;), PHP_URL_SCHEME)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">At that point wp_parse_url() is not available yet, because it is defined in wp-includes\/http.php, which WordPress loads later in the bootstrap sequence.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Generic reproduction:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">curl -i -H &#8216;Host: example.test&#8217; http:\/\/127.0.0.1:8081\/robots.txt<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Observed result:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">PHP Fatal error: Uncaught Error: Call to undefined function wp_parse_url()<br \/>Stack: common-functions.php -&gt; bwp_serve_advanced_cache() -&gt; advanced-cache.php -&gt; wp-settings.php<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The issue may be hidden on public HTTPS traffic when the proxy supplies an HTTPS signal, but it remains reproducible for direct origin HTTP requests, health checks, audits, or proxy configurations where HTTPS is not exposed through $_SERVER[&#8216;HTTPS&#8217;].<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The relevant advanced-cache.php and common-functions.php code is unchanged between BerqWP 4.1.11 and 4.1.12, so the issue is still present in 4.1.12.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Suggested fix:<br \/>Because this code executes before the full WordPress bootstrap, it should avoid calling functions that are not guaranteed to exist. For the absolute home URL, a minimal fix would be:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">parse_url((string) get_option(&#8216;home&#8217;), PHP_URL_SCHEME)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Alternatively, use a guarded fallback:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">function_exists(&#8216;wp_parse_url&#8217;)<br \/>? wp_parse_url((string) get_option(&#8216;home&#8217;), PHP_URL_SCHEME)<br \/>: parse_url((string) get_option(&#8216;home&#8217;), PHP_URL_SCHEME)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">A fail-open guard around the early cache bootstrap would also prevent an optional cache layer from taking down the whole WordPress request.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">I would avoid loading wp-includes\/http.php manually or defining a wp_parse_url() polyfill in the drop-in, because WordPress later loads that file itself and this could cause duplicate declarations or bootstrap incompatibilities.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Could you please confirm and include an upstream fix in the next release?<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank you.<\/p>\n","protected":false},"template":"","class_list":["post-18996616","topic","type-topic","status-publish","hentry","topic-tag-advanced-cache","topic-tag-fatal-error","topic-tag-wordpress-bootstrap"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18996616","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":0,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/18996616\/revisions"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=18996616"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}