Your Trusted Partner

Category: Wordpress Support Manager

How do I set W3 total cache to automatically purge once every day?

W3TC offers some functions to flush caches[1]:

flush_pgcache(); // Page cache
flush_dbcache(); // Database cache
flush_minify(); // Minify cache
flush_all(); // All caches

And you can call it like this:

 

So, if you need daily purging of all caches you could use schedule recurring cron event for whatever function you want[2]. Here’s an example code you can try. I haven’t had a chance to test it though. Drop it in your theme’s functions.php file. You could create a plugin if you wanted for this too.

// Scheduled Action Hook

function w3_flush_cache( ) {
$w3_plugin_totalcache->flush_all();
}

// Schedule Cron Job Event

function w3tc_cache_flush() {
if ( ! wp_next_scheduled( ‘w3_flush_cache’ ) ) {
wp_schedule_event( current_time( ‘timestamp’ ), ‘daily’, ‘w3_flush_cache’ );
}
}

add_action( ‘wp’, ‘w3tc_cache_flush’ );

Hope that helps.

Footnotes

[1] W3 Total Cache plugin integration

[2] Function Reference/wp schedule event

 Viktor Nagornyy

Customize the Protected Text

Adding codes in functions.php

function my_password_form() {
global $post;
$label = ‘pwbox-‘.( empty( $post->ID ) ? rand() : $post->ID );
$o = ‘<form action=”‘ . esc_url( site_url( ‘wp-login.php?action=postpass’, ‘login_post’ ) ) . ‘” method=”post”>
‘ . __( “<h2 style=’color:#e74c3c’>It’s a premium post , to get password for this post , please contact with support manager : <a href=’mailto:ashik685@gmail.com’>ashik685@gmail.com</a></h2>” ) . ‘
<label for=”‘ . $label . ‘”>’ . __( “Password:” ) . ‘ </label><input name=”post_password” id=”‘ . $label . ‘” type=”password” size=”20″ maxlength=”20″ /><input type=”submit” name=”Submit” value=”‘ . esc_attr__( “Submit” ) . ‘” />
</form>
‘;
return $o;
}
add_filter( ‘the_password_form’, ‘my_password_form’ );

© 2020 Webdesigncr3ator

Theme by Anders NorenUp ↑