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();
}
}
@heyfletch
Copy link
Author

Place this file in the wp-content/mu-plugins directory

@damashe
Copy link

damashe commented Apr 23, 2019

Thanks for this, I just ran into this exact problem.
My quick fix was to manually upload the folder of Elementor CSS.

@heyfletch
Copy link
Author

@damashe, glad you could use it. I'm not sure you'd need to upload the folder. I believe simply visiting the pages that had changed should generate the css files. I know it does if they don't exist, but I can't remember if it will regenerate existing files. But then you could just go to Regenerate CSS from the Elementor > Tools menu.

@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