Skip to content

Fix: use home_url() instead of site_url() in get_current_url_supercache_dir - #1024

Open
kraftbj wants to merge 8 commits into
trunkfrom
cherry-pick/613-home-url-supercache-dir
Open

kraftbj wants to merge 8 commits into
trunkfrom
cherry-pick/613-home-url-supercache-dir

Conversation

@kraftbj

@kraftbj kraftbj commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Replace site_url() with home_url() in get_current_url_supercache_dir(), since permalinks are relative to the home URL, not the site URL (these differ when WordPress is installed in a subdirectory).
  • Use wp_parse_url( $permalink, PHP_URL_PATH ) to extract the URI path instead of string-replacing with $wp_cache_home_path, which doesn't work reliably in multisite installations.
  • Add strict type checking to in_array() call, and skip that check when REQUEST_URI is not set (WP-CLI, cron).
  • Fall back to the front page when get_permalink() does not return a string, instead of passing false to str_contains().
  • Update the two integration tests in SupercacheDirCaseTest that set $wp_cache_home_path to filter the home and siteurl options instead. The lowercasing test now uses a site at /Blog, which is the subsite case this fixes: it fails against the old code and passes with this change.

Originally proposed by @stodorovic in #613.

See #613

Test plan

  • Verify cache directory resolution on a standard single-site install.
  • Verify cache directory resolution on a multisite install.
  • Verify cache directory resolution when WordPress is installed in a subdirectory (site URL differs from home URL).
  • Confirm get_current_url_supercache_dir() returns the correct path for individual post IDs.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts supercache directory resolution to use the WordPress “home” URL and more robust URL parsing, improving correctness for subdirectory installs and multisite setups (see #613 / #613).

Changes:

  • Replaces site_url() with home_url() when deriving the permalink-relative cache path.
  • Uses wp_parse_url( $permalink, PHP_URL_PATH ) instead of string replacement against $wp_cache_home_path.
  • Enables strict comparison for the in_array() check against $cached_direct_pages.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread wp-cache-phase2.php Resolved
Comment thread wp-cache-phase2.php Resolved
@kraftbj
kraftbj force-pushed the cherry-pick/613-home-url-supercache-dir branch from 34da52d to 65fb755 Compare April 7, 2026 22:10
stodorovic and others added 7 commits April 7, 2026 17:13
…-url-supercache-dir

# Conflicts:
#	wp-cache-phase2.php
The chained isset() rewrite behaved the same as the original and
overlaps the multisite refactor in PR 1022.
get_current_url_supercache_dir() now takes the path from the permalink,
so the two tests that set $wp_cache_home_path no longer exercise it.
Filter home and siteurl instead, which also covers a subsite whose path
differs from the main site's.
@kraftbj
kraftbj marked this pull request as ready for review November 11, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants