Skip to content

Instantly share code, notes, and snippets.

@kierzniak
Last active February 26, 2019 19:30
Show Gist options
  • Save kierzniak/f686cedac0d82b20726cfc17561f9395 to your computer and use it in GitHub Desktop.
Save kierzniak/f686cedac0d82b20726cfc17561f9395 to your computer and use it in GitHub Desktop.
Remove assets from Swift booster to refresh merged css file
<?php
/**
* Remove assets from Swift booster to refresh merged css file
*
* Swift performance lite is keeping some local assets source in booster which
* prevent from refreshing e.g. css files which may change frequently like in
* Elemetor.
*
* @author Motivast motivast.com
* @copyright 2018 - present, Motivast
*
* @license https://www.gnu.org/licenses/old-licenses/gpl-2.0.txt GPL-2.0-or-later
*
* @link https://gist.github.com/kierzniak/f686cedac0d82b20726cfc17561f9395
*/
function motivast_clear_booster_before_cache_warmup() {
$action = filter_input( INPUT_GET, 'swift-performance-action', FILTER_SANITIZE_STRING );
$nonce = filter_input( INPUT_GET, '_wpnonce', FILTER_SANITIZE_STRING );
if ( 'clear-all-cache' === $action && $nonce && wp_verify_nonce( $nonce, 'clear-swift-cache') ){
delete_transient( 'swift_performance_prebuild_booster' );
}
}
// Fitler has priority set to 5 to execute before assets warmup
add_filter( 'admin_init', 'motivast_clear_booster_before_cache_warmup', 5 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment