| 1 |
<?php |
| 2 |
|
| 3 |
if (!defined('ABSPATH')) exit; |
| 4 |
|
| 5 |
use BerqWP\BerqWP; |
| 6 |
|
| 7 |
class berqElementor extends berqIntegrations |
| 8 |
{ |
| 9 |
|
| 10 |
function __construct() |
| 11 |
{ |
| 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']); |
| 20 |
} |
| 21 |
|
| 22 |
function detect() { |
| 23 |
return class_exists( '\Elementor\Plugin' ); |
| 24 |
} |
| 25 |
|
| 26 |
function flush_page_cache($post_id, $editor_data) |
| 27 |
{ |
| 28 |
|
| 29 |
$post_url = get_permalink($post_id); |
| 30 |
berqCache::purge_page($post_url, true); |
| 31 |
} |
| 32 |
|
| 33 |
function handle_flush_cache() { |
| 34 |
|
| 35 |
if (!$this->detect()) { |
| 36 |
return; |
| 37 |
} |
| 38 |
|
| 39 |
berqCache::stale_cloud_assets(); |
| 40 |
} |
| 41 |
|
| 42 |
function cdn_purge_static_post($meta_id, $post_id, $meta_key, $meta_value) |
| 43 |
{ |
| 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 |
} |
| 62 |
} |
| 63 |
|
| 64 |
new berqElementor(); |
| 65 |
|