Clear Cache For Widgets

Purges all cache on WPEngine, W3 Total Cache, WP Super Cache when updating a widget.

Author:Webhead LLC (profile at wordpress.org)
WordPress version required:3.8
WordPress version tested:6.4.2
Plugin version:2.1.1
Added to WordPress repository:24-01-2014
Last updated:21-01-2024
Rating, %:96
Rated by:27
Plugin URI:https://webheadcoder.com/clear-cache-for-me/
Total downloads:518 892
Active installs:40 000+
plugin download
Click to start download

W3 Total Cache and WP Super Cache are great caching plugins, but they do not know when a widget is updated. WPEngine is the best place to host your WordPress installation, but their caching system is no smarter when it comes to updating widgets and menus. I created this plugin because my website did not see any changes when saving widgets or menus using these caching systems. Clear Cache For Me will purge ALL your cache each time you do a save without having to press an additional button. It may be overkill, which may be why it’s not built in, but some people need simplicity.

In addition to clearing those pesky caching engines, Clear Cache for Me can force your browser to reload your current theme’s CSS and JS files. I modify my theme’s CSS and JS files every so often and always have trouble with the browser not getting the latest version. So now after clicking on the “Clear Cache Now!” button on the dashboard the browser will be forced to reload the current theme’s CSS and JS files. If you do not click the “Clear Cache Now!” button, the browser will cache the CSS and JS files like it normally does.

The popular Qode themes has a options to set your own custom CSS and JS. Sometimes you may not see your changes for a long while because your browser is trying to get the cached file. Whenever you save your Qode’s options, the CSS and JS files will be forced to reload in the browser on the public side.

Works with the following caching plugins:

  • Autoptimize
  • Breeze Cache
  • Cache Enabler
  • GoDaddy Cache
  • Kinsta Cache
  • LiteSpeed Cache
  • Elementor (CSS cache)
  • Premium Addons for Elementor
  • SiteGround SuperCacher
  • WP Fastest Cache
  • WP Optimize Cache
  • WP Rocket
  • WP Super Cache
  • W3 Total Cache
  • WPEngine Cache

Clears all cache for following actions (requires a caching system above to be active):

  • When Widgets are saved.
  • When Customizer is saved.
  • When Menus are saved.
  • When a fields in Advanced Custom Fields are saved.
  • When a Contact Form 7 form is saved.
  • When a Formidable Form form is saved.
  • When WooThemes settings are saved.
  • When NextGen Gallery albums and galleries are updated (beta – may not clear cache on all actions).
  • When Qode options are saved this plugin forces browsers to reload the custom css and custom js.
  • When a WP Forms forms or settings are saved.
  • When WooCommerce settings are saved. (Cache should already be clearing when products are saved.)
  • When settings from the Insert Headers and Footers plugin by WPBeginner are saved.
  • When Settings from a settings page is saved. This includes settings from WordPress core, Yoast SEO, and most other plugins using the Settings API.
  • When WordPress is updated.
  • When plugins are updated, activated, and deactivated.

See the plugin’s homepage for more details.

Note: Since some caching systems run in the shutdown hook, this plugin also runs in that hook. This means if PHP does not have enough time, some code including any hooks within the ccfm_clear_cache_for_all() function are not guaranteed to run. If you need code to run, consider using the ccfm_clear_cache_for_me_setup hook.

Developer Options

ccfm_supported_caching_exists

Use this filter to determine if this plugin should do anything including showing the button on the dashboard. Return true if a caching system is supported.
Default: True if any of the supported caching systems is active.
See Example 1 below.

ccfm_admin_init or ccfm_init_actions

Use this action to add hooks when cache is to be cleared. Or do any other setup activity.

ccfm_clear_cache_for_me_before

Use this action to clear cache from an unsupported caching system before the default caching systems clear their cache.

ccfm_clear_cache_for_me

Use this action to clear cache from an unsupported caching system after the default caching systems clear their cache.

Example

If you were using an unsupported caching system you’ll need to identify the caching plugin’s class or function which clears the cache. As an example, if the unsupported caching system called the MyOtherCache::clear_all() function, you would use the following code to get this plugin to clear the cache.

<?php
function my_other_cache_enable( $return = false ) {
    if ( class_exists( 'MyOtherCache' ) )
        return true;
    return $return;
}
add_filter('ccfm_supported_caching_exists', 'my_other_cache_enable');

function my_other_cache_clear() {
    if ( my_other_cache_enable() )
        MyOtherCache::clear_all();
}
add_action('ccfm_clear_cache_for_me', 'my_other_cache_clear');

Screenshots
ChangeLog