keycdn / cache-enabler

A lightweight caching plugin for WordPress that makes your website faster by generating static HTML files.
https://wordpress.org/plugins/cache-enabler/
123 stars 46 forks source link

admin bar button for clearing specific URLs does not work for installations in a subdirectory #126

Closed digilist closed 4 years ago

digilist commented 4 years ago

I noticed that in my WordPress the cache is not cleared correctly. I did some debugging and think that it is related to my setup which runs WordPress in a sub directory.

Let's assume my blog runs under https://example.com/blog.

When deleting the cache for a specific URL I noticed that cache-enabler tries to delete the cache in this directory: [prefix]/cache-enabler/example.com/blog/blog/[...]. So the /blog is duplicated in the path even though the cache file is stored in /blog/[...] and not /blog/blog/[...].

So I did some debugging and tried to find the source for this incorrect path and found this line of code:

https://github.com/keycdn/cache-enabler/blob/aa39d96715028284b67a70bc12b001579673fc55/inc/cache_enabler.class.php#L898

The result of home_url() is https://example.com/blog and add_query_arg(null, null) results in /blog/[...]. The combined result then is https://example.com/blog/blog/[...].

So I think that code is the reason for the invalid path and why the deletion fails. As I am not that experienced with WordPress and do not know a fix yet, I did not submit a pull request. But I appreciate any help on this 🙂

coreykn commented 4 years ago

You're right, this is causing the subdirectory that the installation is in to be duplicated. This has been the current behavior since version 1.1.0 (d91a78b). Thanks for investigating this issue @digilist. Turns out I just fixed a similarly related issue in PR #125. I'll see what would be best to fix this and will have a solution within the next day or two.

digilist commented 4 years ago

That's great, thank you! :)