Skip to content

Commit

Permalink
Improve WP_CACHE removal. See: #509
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswsinc committed Jul 24, 2015
1 parent b2f7f0e commit 4ee609a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions zencache/zencache.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -2108,8 +2108,8 @@ public function remove_wp_cache_from_wp_config()
if(!preg_match('/([\'"])WP_CACHE\\1/i', $wp_config_file_contents))
return $wp_config_file_contents; // Already gone.

if(preg_match('/define\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/i', $wp_config_file_contents))
return $wp_config_file_contents; // It's already disabled; no need to modify this file.
if(preg_match('/define\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:0|FALSE|NULL|([\'"])0?\\2)\s*\)\s*;/i', $wp_config_file_contents) && !is_writable($wp_config_file))

This comment has been minimized.

Copy link
@jaswrks

jaswrks Jul 27, 2015

@raamdev I feel that the reason for multiple definitions in some rare cases, is because this WP_CACHE removal routine is returning true whenever it finds an existing FALSE-like value. Instead, this routine should remove any WP_CACHE definition that it finds, even if the existing value is FALSE-like.

However, there is one exception. If the wp-config.php file isn't writable to begin with, we can't write to it, and thus, if we are trying to remove and it's already a FALSE-like value that is not writable, then a removal routine can simply return true in that special case; i.e., WP_CACHE is already off :-)

Therefore, by adding this !is_writable() check we continue past this point. Thereby avoiding the duplicate entry problem that we are trying to resolve. The duplicate entry being a result of this method being called upon to do it's job, and failing--right before we add WP_CACHE in another method.

This comment has been minimized.

Copy link
@raamdev

raamdev Jul 27, 2015

Contributor

@jaswsinc Thanks for explaining. I'm still a little fuzzy on how this fixes the issue (an issue which I originally reproduced in an environment where there were no issues writing to wp-config.php), but I just tried reproducing the original double-definition issue with WP Super Cache → ZenCache using this updated code, and I was not able to reproduce it. So, the issue appears to be fixed.

return $wp_config_file_contents; // It's already disabled, and since we can't write to this file let's let this slide.

if(!($wp_config_file_contents = preg_replace('/define\s*\(\s*([\'"])WP_CACHE\\1\s*,\s*(?:\-?[0-9\.]+|TRUE|FALSE|NULL|([\'"])[^\'"]*\\2)\s*\)\s*;/i', '', $wp_config_file_contents)))
return ''; // Failure; something went terribly wrong here.
Expand Down

0 comments on commit 4ee609a

Please sign in to comment.