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

update WP-CLI clear subcommand #262

Closed coreykn closed 3 years ago

coreykn commented 3 years ago

Update the WP-CLI clear subcommand to check for an empty string instead of using the empty() function. This will make it so wp cache-enabler clear --ids=0, wp cache-enabler clear --urls=0, and wp cache-enabler clear --sites=0 will not clear the complete cache. wp cache-enabler clear --sites=0 will now clear the current blog ID due to how the get_site() function works, while the others will now not clear anything.

The status returned by WP-CLI will be improved when the return handling is improved across the code base (due to the changes introduced with the new cache iterator). That will allow WP-CLI to indicate whether or not the cache was actually cleared. For now the status being returned stays as it has been.

Add an empty() check to the cache iterator to prevent the Cache_Enabler_Disk::get_cache_dir() method from returning the cache directory to the currently requested URL (updating what was initially added in PR #237).