Skip to content

Instantly share code, notes, and snippets.

@heyfletch
Last active February 14, 2022 14:14
Show Gist options
  • Save heyfletch/769c64ad1fab8679032b076433afafd1 to your computer and use it in GitHub Desktop.
Save heyfletch/769c64ad1fab8679032b076433afafd1 to your computer and use it in GitHub Desktop.
Clear Elementor Cache After a WP Migrate DB Pro Migration - Must Use Plugin (mu-plugins)
<?php
/*
Plugin Name: FD Clear Elementor Cache After WP Migrate DB Migration
Plugin URI: https://gist.github.com/heyfletch/769c64ad1fab8679032b076433afafd1
Description: Deletes CSS in uploads/elementor/css, which auto-regenerates on pageload. This clears the cache locally and remotely. Must-use plugin (mu-plugin).
Author: Fletcher Digital
Version: 0.1.1
Author URI: https://fletcherdigital.com
*/
// Whitelist Elementor to load during a migration (avoids Migrate DB Pro's Compatibility mode)
add_filter( 'wpmdb_compatibility_plugin_whitelist', function ( $plugins ) {
$plugins[] = 'elementor';
return $plugins;
} );
add_action( 'wpmdb_migration_complete', 'fd_clear_elementor_cache' );
function fd_clear_elementor_cache() {
// Check if Elementor installed and activated
if ( did_action( 'elementor/loaded' ) ) {
// clear Elementor cache
\Elementor\Plugin::instance()->files_manager->clear_cache();
}
}
@lukosevicius
Copy link

Thanks! Works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment