PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.2
Elementor Website Builder – more than just a page builder v3.32.2
4.3.0-beta3 4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 All 452 releases
← All changes | modules/pro-free-trial-popup/module.php +31 -24 4.1.03.32.2 View file →
@@ -12,9 +12,8 @@
12 12 use Elementor\Core\Experiments\Manager as Experiments_Manager;
13 13 use Elementor\Core\Utils\Ab_Test;
14 14 use Elementor\Core\Isolation\Elementor_Adapter;
15 15 use Elementor\Core\Isolation\Elementor_Adapter_Interface;
16 -use Elementor\Includes\EditorAssetsAPI;
17 16 use Elementor\Modules\ElementorCounter\Module as Elementor_Counter;
18 17 use Elementor\Utils;
19 18 use Elementor\Plugin;
20 19
@@ -33,9 +32,8 @@
33 32 const EXTERNAL_DATA_URL = 'https://assets.elementor.com/pro-free-trial-popup/v1/pro-free-trial-popup.json';
34 33 const ACTIVE = 'active';
35 34
36 35 private Elementor_Adapter_Interface $elementor_adapter;
37 - private array $external_data;
38 36
39 37 public function __construct() {
40 38 parent::__construct();
41 39
@@ -50,14 +48,8 @@
50 48 if ( Utils::has_pro() ) {
51 49 return;
52 50 }
53 51
54 - $this->external_data = $this->get_external_data();
55 -
56 - if ( ! EditorAssetsAPI::has_valid_nested_array( $this->external_data, [ self::MODULE_NAME, 0 ] ) ) {
57 - return false;
58 - }
59 -
60 52 $this->elementor_adapter = new Elementor_Adapter();
61 53
62 54 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'maybe_enqueue_popup' ] );
63 55 }
@@ -62,9 +54,9 @@
62 54 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'maybe_enqueue_popup' ] );
63 55 }
64 56
65 57 public function get_name() {
66 - return self::MODULE_NAME;
58 + return 'pro-free-trial-popup';
67 59 }
68 60
69 61 public static function get_experimental_data(): array {
70 62 return [
@@ -121,12 +113,10 @@
121 113 *
122 114 * @return bool True if feature is enabled
123 115 */
124 116 private function is_feature_enabled(): bool {
125 - $popup_data = $this->extract_popup_data( $this->external_data );
126 -
127 - $status = $popup_data['status'] ?? '';
128 - return ! empty( $status ) && self::ACTIVE === $status;
117 + $data = $this->get_external_data();
118 + return ( self::ACTIVE === $data['pro-free-trial-popup'][0]['status'] );
129 119 }
130 120
131 121 /**
132 122 * Get external JSON data
@@ -133,18 +123,30 @@
133 123 *
134 124 * @return array External data or empty array on failure
135 125 */
136 126 private function get_external_data(): array {
137 - $editor_assets_api = new EditorAssetsAPI( $this->get_api_config() );
138 - return $editor_assets_api->get_assets_data();
139 - }
127 + $cached_data = get_transient( 'elementor_pro_free_trial_data' );
140 128
141 - private function get_api_config(): array {
142 - return [
143 - EditorAssetsAPI::ASSETS_DATA_URL => self::EXTERNAL_DATA_URL,
144 - EditorAssetsAPI::ASSETS_DATA_TRANSIENT_KEY => '_elementor_pro_free_trial_data',
145 - EditorAssetsAPI::ASSETS_DATA_KEY => self::MODULE_NAME,
146 - ];
129 + if ( false !== $cached_data ) {
130 + return $cached_data;
131 + }
132 +
133 + $response = wp_remote_get( self::EXTERNAL_DATA_URL );
134 +
135 + if ( is_wp_error( $response ) ) {
136 + return [];
137 + }
138 +
139 + $body = wp_remote_retrieve_body( $response );
140 + $data = json_decode( $body, true );
141 +
142 + if ( ! is_array( $data ) ) {
143 + return [];
144 + }
145 +
146 + set_transient( 'elementor_pro_free_trial_data', $data, HOUR_IN_SECONDS );
147 +
148 + return $data;
147 149 }
148 150
149 151 /**
150 152 * Check if current visit is before the 4th visit
@@ -196,9 +198,10 @@
196 198 ELEMENTOR_VERSION,
197 199 true
198 200 );
199 201
200 - $popup_data = $this->extract_popup_data( $this->external_data );
202 + $external_data = $this->get_external_data();
203 + $popup_data = $this->extract_popup_data( $external_data );
201 204
202 205 wp_localize_script( self::MODULE_NAME, 'elementorProFreeTrialData', $popup_data );
203 206
204 207 wp_set_script_translations( self::MODULE_NAME, 'elementor' );
@@ -210,9 +213,13 @@
210 213 * @param array $external_data The full external data array
211 214 * @return array Popup data or empty array if not found
212 215 */
213 216 private function extract_popup_data( array $external_data ): array {
214 - return $external_data[ self::MODULE_NAME ][0];
217 + if ( ! isset( $external_data['pro-free-trial-popup'] ) || ! is_array( $external_data['pro-free-trial-popup'] ) ) {
218 + return [];
219 + }
220 +
221 + return $external_data['pro-free-trial-popup'][0];
215 222 }
216 223
217 224 /**
218 225 * Get current user ID