jrunkel
Forum Replies Created
-
Great, thank you!
To show the difference:
When updating a plugin manually in the backend,
$optionslooks like this:Array ( [action] => update [type] => plugin [bulk] => 1 [plugins] => Array ( [0] => elementor/elementor.php ) )But when a non-interactive but automatic update of a plugin occurrs, the it looks like this:
Array ( [plugin] => elementor/elementor.php [type] => plugin [action] => update )If you want to keep it then you’ll need to check for both cases:
if($options['type'] == 'plugin' && (isset($options['plugins']) || isset($options['plugin']))) {Nope, it’s
$options['plugin'](singular!).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); } }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
$optionsparam 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); } } }The debug flags that I added are working properly, yes.
(But this isn’t a solution to the original problem.)
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?
(I’m using the second option “Delete cache and minified CSS/JS”.)
Yes, that’s what I do to fix it.
No, I don’t have any other caching / optimization plugin installed. Not sure how Elementor internally handles CSS, though.
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?