| @@ -3,21 +3,62 @@ | ||
| 3 | 3 | if (!defined('ABSPATH')) exit; |
| 4 | 4 | |
| 5 | 5 | use BerqWP\BerqWP; |
| 6 | 6 | |
| 7 | -class berqElementor extends berqIntegrations { | |
| 8 | - | |
| 9 | - function __construct() { | |
| 7 | +class berqElementor extends berqIntegrations | |
| 8 | +{ | |
| 9 | + | |
| 10 | + function __construct() | |
| 11 | + { | |
| 10 | 12 | // add_action( 'elementor/editor/after_save', [$this, 'flush_page_cache'] ); |
| 13 | + | |
| 14 | + // post update | |
| 15 | + add_action('updated_post_meta', [$this, 'cdn_purge_static_post'], 10, 4); | |
| 16 | + add_action('added_post_meta', [$this, 'cdn_purge_static_post'], 10, 4); | |
| 17 | + | |
| 18 | + // elementor cache flush | |
| 19 | + add_action('elementor/core/files/clear_cache', [$this, 'handle_flush_cache']); | |
| 11 | 20 | } |
| 12 | 21 | |
| 13 | - function flush_page_cache($post_id, $editor_data) { | |
| 22 | + function detect() { | |
| 23 | + return class_exists( '\Elementor\Plugin' ); | |
| 24 | + } | |
| 14 | 25 | |
| 15 | - $post_url = get_permalink( $post_id ); | |
| 26 | + function flush_page_cache($post_id, $editor_data) | |
| 27 | + { | |
| 28 | + | |
| 29 | + $post_url = get_permalink($post_id); | |
| 16 | 30 | berqCache::purge_page($post_url, true); |
| 31 | + } | |
| 17 | 32 | |
| 33 | + function handle_flush_cache() { | |
| 34 | + | |
| 35 | + if (!$this->detect()) { | |
| 36 | + return; | |
| 37 | + } | |
| 38 | + | |
| 39 | + berqCache::stale_cloud_assets(); | |
| 18 | 40 | } |
| 19 | 41 | |
| 42 | + function cdn_purge_static_post($meta_id, $post_id, $meta_key, $meta_value) | |
| 43 | + { | |
| 20 | 44 | |
| 45 | + if (!$this->detect()) { | |
| 46 | + return; | |
| 47 | + } | |
| 48 | + | |
| 49 | + if ('_elementor_css' !== $meta_key) { | |
| 50 | + return; | |
| 51 | + } | |
| 52 | + | |
| 53 | + if (!berqwp_can_use_cloud()) { | |
| 54 | + return; | |
| 55 | + } | |
| 56 | + | |
| 57 | + global $berq_log; | |
| 58 | + $berq_log->info("Elementor regenerating css detected"); | |
| 59 | + | |
| 60 | + berqCache::stale_cloud_assets(); | |
| 61 | + } | |
| 21 | 62 | } |
| 22 | 63 | |
| 23 | -new berqElementor(); | |
| 64 | +new berqElementor(); | |