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

cache enabler activation not adding define('WP_CACHE', true); #65

Closed centminmod closed 4 years ago

centminmod commented 4 years ago

I just did a fresh test install of Wordpress 5.3.2 with cache enabler on CentOS 7.7 64bit, Nginx 1.17.8 with PHP 7.4.2 and on activation of plugin, define('WP_CACHE', true); is not being added to wp-config.php. The advanced-cache.php is being properly copied to wp-content directory though. So I manually added define('WP_CACHE', true); to wp-config.php.

However, it seems to properly add define('WP_CACHE', true); to wp-config.php when using PHP 7.3.14 !

On deactivation of cache enabler plugin, define('WP_CACHE', true); is properly removed on wp-config.php. So this suggests it isn't a wp-config.php permissions issue at least ? So what would prevent the auto addition of define('WP_CACHE', true); to wp-config.php on cache enable plugin activation ? PHP 7.4 vs 7.3 related ? I have tried with autoptimize related wp plugins disabled as well and same issue.

php -v
PHP 7.4.2 (cli) (built: Jan 29 2020 04:35:37) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.2, Copyright (c), by Zend Technologies

php -v
PHP 7.3.14 (cli) (built: Feb  3 2020 23:30:56) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.14, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.3.14, Copyright (c) 1999-2018, by Zend Technologies
WP-CLI 2.4.0
WP-Home    http://cache-enabler.domain.com
WP-SiteURL http://cache-enabler.domain.com
WordPress  version:   5.3.2
Database   revision:  45805
TinyMCE    version:   4.960  (4960-20190918)
Package    language:  en_US
+--------------------+----------+--------+---------+
| name               | status   | update | version |
+--------------------+----------+--------+---------+
| akismet            | inactive | none   | 4.1.3   |
| autoptimize        | active   | none   | 2.6.1   |
| autoptimize-gzip   | active   | none   | 0.1     |
| cache-enabler      | active   | none   | 1.3.4   |
| cdn-enabler        | inactive | none   | 1.0.9   |
| classic-editor     | active   | none   | 1.5     |
| disable-xml-rpc    | active   | none   | 1.0.1   |
| sucuri-scanner     | active   | none   | 1.8.22  |
| advanced-cache.php | dropin   | none   |         |
+--------------------+----------+--------+---------+
centminmod commented 4 years ago

seems with PHP 7.3.14 if cache enabler is activated via wp-admin it only sometimes adds define('WP_CACHE', true); to wp-config.php.

but if i use wp-cli command line to activate, it always adds define('WP_CACHE', true); to wp-config.php.

wp plugin deactivate cache-enabler
Plugin 'cache-enabler' deactivated.
Success: Deactivated 1 of 1 plugins.
wp plugin activate cache-enabler  
Plugin 'cache-enabler' activated.
Success: Activated 1 of 1 plugins.
cat wp-config.php | grep -w WP_CACHE
define('WP_CACHE', true); // Added by Cache Enabler

but deactivating cache enabler via wp-admin will ALWAYS remove define('WP_CACHE', true); from wp-config.php - just not re-add it on re-activating via wp-admin.

settings

wp option get cache-enabler --format=json | jq
{
  "expires": 6,
  "new_post": 1,
  "new_comment": 1,
  "webp": 0,
  "clear_on_upgrade": 1,
  "compress": 1,
  "excl_ids": "",
  "excl_regexp": "",
  "excl_cookies": "",
  "incl_attributes": "",
  "minify_html": 0
}
svenba commented 4 years ago

Thanks for the detailed report! Is there anything in the error log maybe?

centminmod commented 4 years ago

there doesn't seem to be any errors in PHP error logs

coreykn commented 4 years ago

As always, thanks for the detail you put into your issues @centminmod. When investigating this issue I've been unable to replicate the same behavior. The only change that has been made so far that I'm aware of related to setting the WP_CACHE constant would be in PR #102. Even checking out the commit before this change I can't replicate this issue, so I don't think that made a difference.

The only time I can replicate similar behavior, regardless of the PHP version or how the plugin is activated/deactivated, is when deactivating Cache Enabler and then immediately activating it after. This occurs because the constant is still defined as true, which I believe is caused by the Cache Enabler script not being completed yet. This means Cache_Enabler::_set_wp_cache() is not called and the constant is not set in the wp-config.php file. Other than not checking if it's true, I'm unsure of a way around this, so if you have any ideas just let me know. Otherwise my plan to provide a link in the WP_CACHE constant warning that will force set the constant will cover this edge case.