Created
January 31, 2026 18:23
-
-
Save mlbd/19d20fff4c90dfb7fcbeddb4a1dca76f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * A) Regenerate Elementor CSS for a specific post. | |
| * Compatible with Elementor 3.34.4+ | |
| */ | |
| function ml_el_regenerate_post_css( $post_id ) { | |
| if ( empty( $post_id ) || wp_is_post_revision( $post_id ) ) { | |
| return; | |
| } | |
| if ( ! class_exists( '\Elementor\Plugin' ) ) { | |
| return; | |
| } | |
| $run = function() use ( $post_id ) { | |
| $plugin = \Elementor\Plugin::instance(); | |
| // Get the document | |
| $document = $plugin->documents->get( $post_id ); | |
| if ( ! $document || ! $document->is_built_with_elementor() ) { | |
| return; | |
| } | |
| // Delete the CSS file meta to force regeneration | |
| delete_post_meta( $post_id, '_elementor_css' ); | |
| // Get and update the CSS file | |
| $css_file = $document->get_css_file(); | |
| if ( $css_file ) { | |
| $css_file->delete(); | |
| $css_file->update(); | |
| } | |
| }; | |
| if ( did_action( 'elementor/loaded' ) ) { | |
| $run(); | |
| } else { | |
| add_action( 'elementor/loaded', $run, 99 ); | |
| } | |
| } | |
| /** | |
| * B) Clear Elementor's global cache - Exact same method as Tools page | |
| * This mimics what happens when clicking "Clear Files & Data" in Elementor Tools | |
| */ | |
| function ml_el_clear_global_css_js_cache() { | |
| if ( ! class_exists( '\Elementor\Plugin' ) ) { | |
| return; | |
| } | |
| $run = function() { | |
| // This is exactly what Elementor does in ajax_elementor_clear_cache() and admin_post_elementor_site_clear_cache() | |
| \Elementor\Plugin::$instance->files_manager->clear_cache(); | |
| }; | |
| if ( did_action( 'elementor/loaded' ) ) { | |
| $run(); | |
| } else { | |
| add_action( 'elementor/loaded', $run, 99 ); | |
| } | |
| } | |
| /** | |
| * Approach A: per-post CSS regenerate on OWF complete | |
| */ | |
| add_action( 'owf_revision_workflow_complete', function( $post_id ) { | |
| $original_post_id = get_post_meta( $post_id, '_oasis_original', true ); | |
| if ( ! empty( $original_post_id ) ) { | |
| ml_el_regenerate_post_css( $original_post_id ); | |
| } else { | |
| ml_el_clear_global_css_js_cache(); | |
| } | |
| }, 11, 1 ); | |
| /** | |
| * Approach B: global cache clear on OWF complete (enable if you prefer global purge) | |
| */ | |
| // add_action( 'owf_revision_workflow_complete', function( $post_id ) { | |
| // ml_el_clear_global_css_js_cache(); | |
| // }, 11, 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment