• Resolved jrunkel

    (@jrunkel)


    Recently I’ve found that the styles of some websites are broken after automatic updates of WordPress or some plugins. After clearing the cache (especially the minified css files) they rendered fine again.

    For this reason I switched to another cache plugin on one website. Since the issue reoccurred on another website I investigated more and finally found this thread and the resulting solution:
    https://ww.wp.xz.cn/support/topic/auto-clear-cache-after-updates-2/
    https://www.wpfastestcache.com/features/clear-cache-after-theme-or-plugin-update/

    This helps with the problem. But since it requires some active research and manual manipulation of the wp-config.php file I would suggest that you enable this feature by default. Many users do have automatic updates for plugins enabled and wake up a day with a broken website. This is probably not what you want …

    • This topic was modified 4 years, 5 months ago by jrunkel. Reason: changed link of wpfastestcache.com (inserted wrong one in original post)
Viewing 15 replies - 1 through 15 (of 21 total)
  • Plugin Author Emre Vona

    (@emrevona)

    you are right. this feature was like a beta feature. I will make it as a default feature and let you know.

    Thread Starter jrunkel

    (@jrunkel)

    Thanks for your reply. I’d love to see an update for this feature.

    Today my site was broken again after an automatic update of the following plugins:

    – Elementor (from version 3.4.8 to 3.5.0)
    – Essential Addons for Elementor (from version 4.9.6 to 4.9.7)

    This happened though I had added these two lines to the wp-config.php:

    define("WPFC_CLEAR_CACHE_AFTER_PLUGIN_UPDATE", true);
    define("WPFC_CLEAR_CACHE_AFTER_THEME_UPDATE", true);

    Is there any reliable technique as of today, that I can use to prevent this?

    Plugin Author Emre Vona

    (@emrevona)

    are you using another cache system as well or any other optimization plugin?

    Thread Starter jrunkel

    (@jrunkel)

    No, I don’t have any other caching / optimization plugin installed. Not sure how Elementor internally handles CSS, though.

    Plugin Author Emre Vona

    (@emrevona)

    is the problem solved when you clear all cache manually?

    Thread Starter jrunkel

    (@jrunkel)

    Yes, that’s what I do to fix it.

    Thread Starter jrunkel

    (@jrunkel)

    (I’m using the second option “Delete cache and minified CSS/JS”.)

    Plugin Author Emre Vona

    (@emrevona)

    Thread Starter jrunkel

    (@jrunkel)

    I changed them to the following:

    if(defined("WPFC_CLEAR_CACHE_AFTER_PLUGIN_UPDATE") && WPFC_CLEAR_CACHE_AFTER_PLUGIN_UPDATE){
    	if(isset($_GET['DEBUG']) && $_GET['DEBUG']=='PLUGINS') { echo 'Clearing after plugin updates is activated!'; exit; }
    	add_action('upgrader_process_complete', array($this, 'clear_cache_after_update_plugin'), 10, 2);
    }
    
    if(defined("WPFC_CLEAR_CACHE_AFTER_THEME_UPDATE") && WPFC_CLEAR_CACHE_AFTER_THEME_UPDATE){
    	if(isset($_GET['DEBUG']) && $_GET['DEBUG']=='THEME') { echo 'Clearing after theme updates is activated!'; exit; }
    	add_action('upgrader_process_complete', array($this, 'clear_cache_after_update_theme'), 10, 2);
    }

    Calling http://www.mydomain.com/?DEBUG=PLUGINS and http://www.mydomain.com/?DEBUG=THEME I get the defined outputs and exits. I guess that is what you wanted to assure?

    Plugin Author Emre Vona

    (@emrevona)

    are they working properly?

    Thread Starter jrunkel

    (@jrunkel)

    The debug flags that I added are working properly, yes.

    (But this isn’t a solution to the original problem.)

    Plugin Author Emre Vona

    (@emrevona)

    I have no idea.

    Thread Starter jrunkel

    (@jrunkel)

    I added some debugging output to your plugin and traced down the issue. In the two functions you’re checking the type of update which is fine but also you are checking the list of affected plugins/themes. This is where the problem lies because the list of plugins/themes is not present when only a single plugin/theme gets an automatic update.

    The $options param looks like this in these situations:

    Array
    (
        [plugin] => elementor/elementor.php
        [type] => plugin
        [action] => update
    )

    To fix the issue please change these lines:

    public function clear_cache_after_update_plugin($upgrader_object, $options){
    	if($options['action'] == 'update'){
    		if($options['type'] == 'plugin' && isset($options['plugins'])){
    			$this->deleteCache(true);
    		}
    	}
    }
    
    public function clear_cache_after_update_theme($upgrader_object, $options){
    	if($options['action'] == 'update'){
    		if($options['type'] == 'theme' && isset($options['themes'])){
    			$this->deleteCache(true);
    		}
    	}
    }

    to the following:

    public function clear_cache_after_update_plugin($upgrader_object, $options){
    	if($options['action'] == 'update'){
    		if($options['type'] == 'plugin'){
    			$this->deleteCache(true);
    		}
    	}
    }
    
    public function clear_cache_after_update_theme($upgrader_object, $options){
    	if($options['action'] == 'update'){
    		if($options['type'] == 'theme'){
    			$this->deleteCache(true);
    		}
    	}
    }
    Thread Starter jrunkel

    (@jrunkel)

    Or even shorter:

    public function clear_cache_after_update_plugin($upgrader_object, $options){
    	if($options['action'] == 'update' && $options['type'] == 'plugin'){
    		$this->deleteCache(true);
    	}
    }
    
    public function clear_cache_after_update_theme($upgrader_object, $options){
    	if($options['action'] == 'update' && $options['type'] == 'theme'){
    		$this->deleteCache(true);
    	}
    }
    Plugin Author Emre Vona

    (@emrevona)

    why should I remove the isset($options[‘plugins’]) condition? $options[‘plugins’] has already exist.

Viewing 15 replies - 1 through 15 (of 21 total)

The topic ‘Clear Cache after Automatic Updates’ is closed to new replies.