From 65fb755faf27d5bddcaeb34a7448c074b75b81e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Todorovi=C4=87?= <15647032+stodorovic@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:10:20 -0500 Subject: [PATCH 1/5] fix: use home_url() instead of site_url() in get_current_url_supercache_dir --- wp-cache-phase2.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index d3c5ce3d..751f7d86 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -822,7 +822,7 @@ function get_supercache_dir( $blog_id = 0 ) { return trailingslashit( apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) ) ); } function get_current_url_supercache_dir( $post_id = 0 ) { - global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST, $wp_cache_home_path; + global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST; static $saved_supercache_dir = array(); if ( isset( $saved_supercache_dir[ $post_id ] ) ) { @@ -831,14 +831,14 @@ function get_current_url_supercache_dir( $post_id = 0 ) { $DONOTREMEMBER = 0; if ( $post_id != 0 ) { - $site_url = site_url(); + $home_url = home_url(); $permalink = get_permalink( $post_id ); - if ( ! str_contains( $permalink, $site_url ) ) { + if ( ! str_contains( $permalink, $home_url ) ) { /* - * Sometimes site_url doesn't return the siteurl. See https://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made + * Sometimes home_url doesn't return the home url. See https://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made */ $DONOTREMEMBER = 1; - wp_cache_debug( "get_current_url_supercache_dir: WARNING! site_url ($site_url) not found in permalink ($permalink).", 1 ); + wp_cache_debug( "get_current_url_supercache_dir: WARNING! home_url ($home_url) not found in permalink ($permalink).", 1 ); if ( preg_match( '`^(https?:)?//([^/]+)(/.*)?$`i', $permalink, $matches ) ) { if ( $WPSC_HTTP_HOST != $matches[2] ) { wp_cache_debug( "get_current_url_supercache_dir: WARNING! SERVER_NAME ({$WPSC_HTTP_HOST}) not found in permalink ($permalink).", 1 ); @@ -853,10 +853,9 @@ function get_current_url_supercache_dir( $post_id = 0 ) { $uri = ''; } } else { - $uri = str_replace( $site_url, '', $permalink ); - $home_path = $wp_cache_home_path ?? ''; - if ( $home_path !== '' && ! str_starts_with( $uri, $home_path ) ) { - $uri = rtrim( $home_path, '/' ) . $uri; + $uri = wp_parse_url( $permalink, PHP_URL_PATH ); + if ( ! is_string( $uri ) ) { + $uri = ''; } } } else { @@ -882,7 +881,7 @@ function ( $matches ) { $dir = do_cacheaction( 'supercache_dir', $dir ); } $dir = $cache_path . 'supercache/' . $dir . '/'; - if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages ) ) { + if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages, true ) ) { $dir = ABSPATH . $uri . '/'; } $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) ); From a4eed5ec964d225bd28951f8996fc904d87197e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Todorovi=C4=87?= <15647032+stodorovic@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:13:17 -0500 Subject: [PATCH 2/5] fix: split isset() to single argument per call --- plugins/multisite.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/multisite.php b/plugins/multisite.php index 11071752..86943268 100644 --- a/plugins/multisite.php +++ b/plugins/multisite.php @@ -22,7 +22,7 @@ function wp_super_cache_blogs_field( $name, $blog_id ) { $blog_id = (int) $blog_id; - if ( isset( $_GET['id'], $_GET['action'], $_GET['_wpnonce'] ) + if ( isset( $_GET['id'] ) && isset( $_GET['action'] ) && isset( $_GET['_wpnonce'] ) && $blog_id === filter_input( INPUT_GET, 'id', FILTER_VALIDATE_INT ) && wp_verify_nonce( $_GET['_wpnonce'], 'wp-cache' . $blog_id ) ) { From 0934babd4e71bfdd6a6ff3cb9aeb601d3af7c34c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Todorovi=C4=87?= <15647032+stodorovic@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:14:37 -0500 Subject: [PATCH 3/5] fix: address PHPCS errors in get_current_url_supercache_dir --- wp-cache-phase2.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 751f7d86..29cf1b0a 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -822,7 +822,7 @@ function get_supercache_dir( $blog_id = 0 ) { return trailingslashit( apply_filters( 'wp_super_cache_supercachedir', $cache_path . 'supercache/' . trailingslashit( strtolower( preg_replace( '/:.*$/', '', str_replace( 'http://', '', str_replace( 'https://', '', $home ) ) ) ) ) ) ); } function get_current_url_supercache_dir( $post_id = 0 ) { - global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST; + global $cached_direct_pages, $cache_path, $wp_cache_request_uri, $WPSC_HTTP_HOST; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase static $saved_supercache_dir = array(); if ( isset( $saved_supercache_dir[ $post_id ] ) ) { @@ -881,7 +881,7 @@ function ( $matches ) { $dir = do_cacheaction( 'supercache_dir', $dir ); } $dir = $cache_path . 'supercache/' . $dir . '/'; - if ( is_array( $cached_direct_pages ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages, true ) ) { + if ( is_array( $cached_direct_pages ) && isset( $_SERVER['REQUEST_URI'] ) && in_array( $_SERVER['REQUEST_URI'], $cached_direct_pages, true ) ) { $dir = ABSPATH . $uri . '/'; } $dir = str_replace( '..', '', str_replace( '//', '/', $dir ) ); From 52fa56ccf09d831ed06813c8404b24ab085bfaa0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C5=A1a=20Todorovi=C4=87?= <15647032+stodorovic@users.noreply.github.com> Date: Tue, 7 Apr 2026 17:15:36 -0500 Subject: [PATCH 4/5] fix: guard against get_permalink() returning false --- wp-cache-phase2.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index 29cf1b0a..e3007420 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -833,7 +833,11 @@ function get_current_url_supercache_dir( $post_id = 0 ) { if ( $post_id != 0 ) { $home_url = home_url(); $permalink = get_permalink( $post_id ); - if ( ! str_contains( $permalink, $home_url ) ) { + if ( ! is_string( $permalink ) ) { + $DONOTREMEMBER = 1; + wp_cache_debug( "get_current_url_supercache_dir: WARNING! get_permalink($post_id) did not return a valid string. Using front page.", 1 ); + $uri = ''; + } elseif ( ! str_contains( $permalink, $home_url ) ) { /* * Sometimes home_url doesn't return the home url. See https://wordpress.org/support/topic/wp-super-cache-not-refreshing-post-after-comments-made */ From fe6d0b2c582413bb63020c7671eea0dc665ffee2 Mon Sep 17 00:00:00 2001 From: Brandon Kraft Date: Tue, 7 Apr 2026 17:19:52 -0500 Subject: [PATCH 5/5] fix: add phpcs ignore for pre-existing DONOTREMEMBER variable --- wp-cache-phase2.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wp-cache-phase2.php b/wp-cache-phase2.php index e3007420..a0bbe103 100644 --- a/wp-cache-phase2.php +++ b/wp-cache-phase2.php @@ -834,7 +834,7 @@ function get_current_url_supercache_dir( $post_id = 0 ) { $home_url = home_url(); $permalink = get_permalink( $post_id ); if ( ! is_string( $permalink ) ) { - $DONOTREMEMBER = 1; + $DONOTREMEMBER = 1; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.VariableNotSnakeCase wp_cache_debug( "get_current_url_supercache_dir: WARNING! get_permalink($post_id) did not return a valid string. Using front page.", 1 ); $uri = ''; } elseif ( ! str_contains( $permalink, $home_url ) ) {