ACF.php
1 year ago
AdvancedMathCaptcha.php
1 year ago
AeliaCurrencySwitcher.php
11 months ago
BeaverBuilder.php
1 year ago
CF_Helper.php
1 year ago
CURCY_MultiCurrency.php
1 year ago
Cloudflare.php
1 year ago
CommonHelpers.php
1 year ago
CookieNotice.php
1 year ago
DownloadManager.php
1 year ago
Elementor.php
6 months ago
Ezoic.php
1 year ago
FusionBuilder.php
1 year ago
GeoTargetingWP.php
1 year ago
GravityForms.php
1 year ago
JetPackNP.php
1 year ago
MPG.php
11 months ago
NginxHelper.php
1 year ago
RC.php
11 months ago
RankMathNP.php
1 year ago
ShortPixel.php
1 year ago
SquirrlySEO.php
1 year ago
TheEventsCalendar.php
1 year ago
ThriveTheme.php
1 year ago
WCML.php
1 year ago
WPBakeryNP.php
1 year ago
WPCacheHelper.php
1 year ago
WPForms.php
1 year ago
WPML.php
1 year ago
WPRocket.php
1 year ago
WooCommerce.php
11 months ago
WoocommerceCacheHandler.php
1 year ago
YoastSEO.php
1 year ago
Elementor.php
66 lines
| 1 | <?php |
| 2 | |
| 3 | namespace NitroPack\Integration\Plugin; |
| 4 | |
| 5 | class Elementor { |
| 6 | |
| 7 | const STAGE = "late"; |
| 8 | |
| 9 | public static function isActive() { |
| 10 | $activePlugins = apply_filters('active_plugins', get_option('active_plugins')); |
| 11 | if (defined('ELEMENTOR_PRO_VERSION') || in_array( 'elementor-pro/elementor-pro.php', $activePlugins )) { |
| 12 | return true; |
| 13 | } |
| 14 | if (defined('ELEMENTOR_VERSION') || in_array( 'elementor/elementor.php', $activePlugins )) { |
| 15 | return true; |
| 16 | } |
| 17 | return false; |
| 18 | } |
| 19 | |
| 20 | public function init($stage) { |
| 21 | if ( ! self::isActive() ) { |
| 22 | return; |
| 23 | } |
| 24 | |
| 25 | add_action( 'save_post', array($this, 'purge_cache_on_custom_code_snippet_update'), 10, 3 ); |
| 26 | add_action( 'elementor/core/files/clear_cache', array($this, 'purge_cache_on_global_settings_update'), 10, 0); |
| 27 | } |
| 28 | |
| 29 | public function purge_cache_on_custom_code_snippet_update( $post_id, $post, $update ) { |
| 30 | |
| 31 | if ( 'elementor_snippet' !== $post->post_type || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || 'auto-draft' === $post->post_status ) { |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | if( strpos( wp_get_raw_referer(), 'post-new' ) > 0 ) { |
| 36 | |
| 37 | if ( empty( $_POST['code'] ) ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | /* If new snippet is added */ |
| 42 | nitropack_sdk_invalidate(NULL, NULL, 'Elementor Custom Code Snippet Added'); |
| 43 | |
| 44 | } else { |
| 45 | |
| 46 | /* If old snippet is Updated */ |
| 47 | nitropack_sdk_invalidate(NULL, NULL, 'Elementor Custom Code Snippet Updated'); |
| 48 | |
| 49 | } |
| 50 | |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Listen for Elementor CSS Cache Clearing (The "Regenerate CSS" Tool) |
| 55 | * Perform light cache purge |
| 56 | */ |
| 57 | public function purge_cache_on_global_settings_update() { |
| 58 | if ( function_exists( 'nitropack_sdk_purge' ) ) { |
| 59 | if ( nitropack_sdk_purge( NULL, NULL, 'Light purge, because of Elementor Settings/CSS Update', \NitroPack\SDK\PurgeType::LIGHT_PURGE )) { |
| 60 | \NitroPack\WordPress\NitroPack::getInstance()->getLogger()->notice( 'Light purge, because of Elementor Settings/CSS Update' ); |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | } |
| 66 |