Support » Plugin: W3 Total Cache » Clear cache programmatically

  • I’m looking for a way to clear cache programmatically from the frontend– in other words, a function or action I can call, without being logged in, to flush all w3tc caches. This would have the same effect as the “Empty all caches” button on the wp admin toolbar, but be accessible in my own theme files. for example,

    function my_clear_all_caches() {
     	if(isset($_GET['clear_cache'])) {
     		flush_all_w3tc_cache(); // This is not a real function; I'm looking for what should be plugged in here
    	}
     }
     add_action('init', 'my_clear_all_caches');

    Many thanks for any help!

    https://wordpress.org/plugins/w3-total-cache/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Snippit of switch case:

    case 'All':
    		if ( function_exists( 'w3tc_pgcache_flush' ) )
    		{
    			w3tc_pgcache_flush();
    		}
    		else
    		{
    			$notices[] = 'Error, function w3tc_pgcache_flush is not present';
    		}
    		if ( function_exists( 'w3tc_minify_flush' ) )
    		{
    			w3tc_minify_flush();
    		}
    		else
    		{
    			$notices[] = 'Error, function w3tc_minify_flush is not present';
    		}
    		if ( function_exists( 'w3tc_dbcache_flush' ) )
    		{
    			w3tc_dbcache_flush();
    		}
    		else
    		{
    			$notices[] = 'Error, function w3tc_dbcache_flush is not present';
    		}
    		if ( function_exists( 'w3tc_objectcache_flush' ) )
    		{
    			w3tc_objectcache_flush();
    		}
    		else
    		{
    			$notices[] = 'Error, function w3tc_objectcache_flush is not present';
    		}
    		break;

    Are you interested in a plugin that will clear your caches based on your schedule? I’ve build one 🙂

    wp-cli is also great for that

    wp w3-total-cache flush
    wp w3-total-cache pgcache_cleanup
    wp w3-total-cache querystring
    wp w3-total-cache cdn_purge

    etc

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Clear cache programmatically’ is closed to new replies.