PluginProbe ʕ •ᴥ•ʔ
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization / 1.19.4
NitroPack – Performance, Page Speed & Cache Plugin for Core Web Vitals, CDN & Image Optimization v1.19.4
1.19.8 1.19.7 1.19.6 1.19.5 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.12.0 1.13.0 1.14.0 1.15.0 1.15.1 1.15.2 1.15.3 1.16.0 1.16.1 1.16.2 1.16.3 1.16.4 1.16.5 1.16.6 1.16.7 1.16.8 1.17.0 1.17.6 1.17.7 1.17.8 1.17.9 1.18.0 1.18.1 1.18.2 1.18.3 1.18.4 1.18.5 1.18.6 1.18.7 1.18.8 1.18.9 1.19.0 1.19.1 1.19.2 1.19.3 1.19.4 1.3.19 1.3.20 1.4.0 1.4.1 1.5.0 1.5.1 1.5.10 1.5.11 1.5.12 1.5.13 1.5.14 1.5.15 1.5.16 1.5.17 1.5.18 1.5.19 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.8.1 1.8.3 1.9.0 1.9.1 1.9.2
nitropack / classes / Integration / Plugin / Elementor.php
nitropack / classes / Integration / Plugin Last commit date
ACF.php 4 months ago AdvancedMathCaptcha.php 1 year ago AeliaCurrencySwitcher.php 11 months ago BeaverBuilder.php 1 year ago CF_Helper.php 5 months ago CURCY_MultiCurrency.php 1 year ago Cloudflare.php 5 months ago CommonHelpers.php 1 year ago CookieNotice.php 1 year ago DownloadManager.php 1 year ago Elementor.php 5 months ago Ezoic.php 1 year ago FusionBuilder.php 1 year ago GeoTargetingWP.php 1 year ago GravityForms.php 2 months 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 2 months 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
128 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/document/after_save', array($this, 'purge_on_kit_update'), 10, 2 );
27
28 // Add AJAX handler for Elementor Tools page cache clearing
29 add_action( 'wp_ajax_nitropack_elementor_clear_cache', array($this, 'ajax_clear_cache') );
30 }
31
32 public function purge_cache_on_custom_code_snippet_update( $post_id, $post, $update ) {
33
34 if ( 'elementor_snippet' !== $post->post_type || defined('DOING_AUTOSAVE') && DOING_AUTOSAVE || 'auto-draft' === $post->post_status ) {
35 return;
36 }
37
38 if( strpos( wp_get_raw_referer(), 'post-new' ) > 0 ) {
39
40 if ( empty( $_POST['code'] ) ) {
41 return;
42 }
43
44 /* If new snippet is added */
45 nitropack_sdk_invalidate(NULL, NULL, 'Elementor Custom Code Snippet Added');
46 } else {
47
48 /* If old snippet is Updated */
49 nitropack_sdk_invalidate(NULL, NULL, 'Elementor Custom Code Snippet Updated');
50 }
51 }
52
53 /**
54 * Handle Global Settings Updates Only (Document of type Kit)
55 * Hook: 'elementor/document/after_save'
56 */
57 public function purge_on_kit_update( $document, $data ) {
58 // Check if the document being saved is a "Kit" (Global Settings)
59 // We strictly check the class name or type to ensure it's not a normal page.
60 $is_kit = (
61 $document instanceof \Elementor\Core\Kits\Documents\Kit ||
62 $document->get_type() === 'kit'
63 );
64
65 if (! $is_kit) {
66 return;
67 }
68
69 $active_kit_id = \Elementor\Plugin::$instance->kits_manager->get_active_id();
70
71 if ( $document->get_id() != $active_kit_id ) {
72 return;
73 }
74
75 if ( function_exists('nitropack_sdk_purge') && nitropack_sdk_purge( NULL, NULL, 'Light purge, because of Elementor Settings/CSS Update', \NitroPack\SDK\PurgeType::LIGHT_PURGE ) ) {
76 \NitroPack\WordPress\NitroPack::getInstance()->getLogger()->notice('Light purge, because of Elementor Settings/CSS Update');
77 }
78 }
79
80 /**
81 * AJAX handler for clearing NitroPack cache from Elementor Tools page
82 * Triggered when user clicks Clear Cache button on Elementor Tools admin page
83 * Hook: 'wp_ajax_nitropack_elementor_clear_cache'
84 */
85 public function ajax_clear_cache() {
86 // Verify nonce for security
87 check_ajax_referer( 'nitropack_elementor_clear_cache', 'nonce' );
88
89 // Check user permissions (same as Elementor's manage_options requirement)
90 if ( ! current_user_can( 'manage_options' ) ) {
91 wp_send_json_error( array( 'message' => 'Permission denied' ) );
92 return;
93 }
94
95 try {
96 // Execute NitroPack light purge
97 if ( function_exists('nitropack_sdk_purge') ) {
98 $result = nitropack_sdk_purge(
99 NULL,
100 NULL,
101 'Light purge triggered from Elementor Tools Clear Cache',
102 \NitroPack\SDK\PurgeType::LIGHT_PURGE
103 );
104
105 if ( $result ) {
106 // Log success
107 \NitroPack\WordPress\NitroPack::getInstance()
108 ->getLogger()
109 ->notice('Light purge triggered from Elementor Tools Clear Cache');
110
111 wp_send_json_success( array( 'message' => 'NitroPack cache cleared successfully' ) );
112 } else {
113 wp_send_json_error( array( 'message' => 'NitroPack cache clearing failed' ) );
114 }
115 } else {
116 wp_send_json_error( array( 'message' => 'NitroPack SDK not available' ) );
117 }
118 } catch ( \Exception $e ) {
119 // Log error
120 \NitroPack\WordPress\NitroPack::getInstance()
121 ->getLogger()
122 ->error('Error clearing NitroPack cache from Elementor Tools: ' . $e->getMessage());
123
124 wp_send_json_error( array( 'message' => 'Error clearing cache: ' . $e->getMessage() ) );
125 }
126 }
127 }
128