From ad95c6df7d863ca0086aebd41dc10d37d40fe5cb Mon Sep 17 00:00:00 2001 From: David Saliba Date: Wed, 18 Mar 2026 02:52:38 +0100 Subject: [PATCH] Fix str_starts_with() null deprecation in get_current_url_supercache_dir On PHP 8.1+, passing null to str_starts_with() as the $needle parameter triggers a deprecation notice. The global $wp_cache_home_path can be null when it is not defined in the cache config, causing: Deprecated: str_starts_with(): Passing null to parameter #2 ($needle) of type string is deprecated in wp-cache-phase2.php on line 857 This coalesces $wp_cache_home_path to an empty string and skips the prefix check entirely when the home path is empty, which avoids both the deprecation warning and the incorrect rtrim(null, '/') call inside the conditional body. Made-with: Cursor --- wp-cache-phase2.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 0cb613de..a968fb8b 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -854,8 +854,9 @@ function get_current_url_supercache_dir( $post_id = 0 ) { } } else { $uri = str_replace( $site_url, '', $permalink ); - if ( ! str_starts_with( $uri, $wp_cache_home_path ) ) { - $uri = rtrim( $wp_cache_home_path, '/' ) . $uri; + $home_path = $wp_cache_home_path ?? ''; + if ( $home_path !== '' && ! str_starts_with( $uri, $home_path ) ) { + $uri = rtrim( $home_path, '/' ) . $uri; } } } else {