PluginProbe
Elementor Website Builder – more than just a page builder / 3.32.0-dev3
Elementor Website Builder – more than just a page builder v3.32.0-dev3
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 +32 -31 4.1.0-dev23.32.0-dev3 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,17 +32,13 @@
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();
39 + $this->elementor_adapter = new Elementor_Adapter();
41 40
42 - if ( ! current_user_can( 'manage_options' ) ) {
43 - return;
44 - }
45 -
46 41 if ( ! Plugin::$instance->experiments->is_feature_active( self::EXPERIMENT_NAME ) ) {
47 42 return;
48 43 }
49 44
@@ -50,21 +45,13 @@
50 45 if ( Utils::has_pro() ) {
51 46 return;
52 47 }
53 48
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 - $this->elementor_adapter = new Elementor_Adapter();
61 -
62 49 add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'maybe_enqueue_popup' ] );
63 50 }
64 51
65 52 public function get_name() {
66 - return self::MODULE_NAME;
53 + return 'pro-free-trial-popup';
67 54 }
68 55
69 56 public static function get_experimental_data(): array {
70 57 return [
@@ -97,9 +84,8 @@
97 84 *
98 85 * @return bool True if popup should be shown
99 86 */
100 87 private function should_show_popup(): bool {
101 -
102 88 if ( ! $this->is_feature_enabled() ) {
103 89 return false;
104 90 }
105 91
@@ -121,12 +107,10 @@
121 107 *
122 108 * @return bool True if feature is enabled
123 109 */
124 110 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;
111 + $data = $this->get_external_data();
112 + return ( self::ACTIVE === $data['pro-free-trial-popup'][0]['status'] );
129 113 }
130 114
131 115 /**
132 116 * Get external JSON data
@@ -133,18 +117,30 @@
133 117 *
134 118 * @return array External data or empty array on failure
135 119 */
136 120 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 - }
121 + $cached_data = get_transient( 'elementor_pro_free_trial_data' );
140 122
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 - ];
123 + if ( false !== $cached_data ) {
124 + return $cached_data;
125 + }
126 +
127 + $response = wp_remote_get( self::EXTERNAL_DATA_URL );
128 +
129 + if ( is_wp_error( $response ) ) {
130 + return [];
131 + }
132 +
133 + $body = wp_remote_retrieve_body( $response );
134 + $data = json_decode( $body, true );
135 +
136 + if ( ! is_array( $data ) ) {
137 + return [];
138 + }
139 +
140 + set_transient( 'elementor_pro_free_trial_data', $data, HOUR_IN_SECONDS );
141 +
142 + return $data;
147 143 }
148 144
149 145 /**
150 146 * Check if current visit is before the 4th visit
@@ -196,9 +192,10 @@
196 192 ELEMENTOR_VERSION,
197 193 true
198 194 );
199 195
200 - $popup_data = $this->extract_popup_data( $this->external_data );
196 + $external_data = $this->get_external_data();
197 + $popup_data = $this->extract_popup_data( $external_data );
201 198
202 199 wp_localize_script( self::MODULE_NAME, 'elementorProFreeTrialData', $popup_data );
203 200
204 201 wp_set_script_translations( self::MODULE_NAME, 'elementor' );
@@ -210,9 +207,13 @@
210 207 * @param array $external_data The full external data array
211 208 * @return array Popup data or empty array if not found
212 209 */
213 210 private function extract_popup_data( array $external_data ): array {
214 - return $external_data[ self::MODULE_NAME ][0];
211 + if ( ! isset( $external_data['pro-free-trial-popup'] ) || ! is_array( $external_data['pro-free-trial-popup'] ) ) {
212 + return [];
213 + }
214 +
215 + return $external_data['pro-free-trial-popup'][0];
215 216 }
216 217
217 218 /**
218 219 * Get current user ID