Skip to content

Instantly share code, notes, and snippets.

@mavas84
Created December 4, 2024 15:02
Show Gist options
  • Save mavas84/a2d07ccf922c46af23ebfc49dc15c13e to your computer and use it in GitHub Desktop.
Save mavas84/a2d07ccf922c46af23ebfc49dc15c13e to your computer and use it in GitHub Desktop.
Prevent cache flush on actions by other themes or plugins
Some plugins flushing page cache all the time and without a reason effectively blocking
page caching functionality.
It's usually done by w3tc_flush_all / w3tc_flush_posts calls.
You may block those by cancelling their functionality by adding hooks to w3tc_preflush_posts / w3tc_preflush_all actions.
W3TC UI buttons send $extras as [ 'ui_action' = 'flush_button' ] value, this one
can be used to still allow flushing by UI button.
Here is the example code:
add_filter( 'w3tc_preflush_posts',
function( $do_flush, $extras ) {
if ( isset( $extras['ui_action'] ) && $extras['ui_action'] == 'flush_button' ) {
return $do_flush;
}
return false;
},
99999, 2 );
add_filter( 'w3tc_preflush_all',
function( $do_flush, $extras ) {
if ( isset( $extras['ui_action'] ) && $extras['ui_action'] == 'flush_button' ) {
return $do_flush;
}
return false;
},
99999, 2 );
Alternatively callstack can be analyzed to filter only some specific plugin by analyzing
result of debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ).
But that's a bit slower solution and tends to stop working on plugin updates.
Outputs the OPML XML format for getting the links defined in the link administration. This can be used to export links from one blog over to another. Links aren't exported by the WordPress export, so this file handles that.
This file is not added by default to WordPress theme pages when outputting feed links. It will have to be added manually for browsers and users to pick up that this file exists.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment