PluginProbe ʕ •ᴥ•ʔ
Elementor Website Builder – more than just a page builder / 4.1.1
Elementor Website Builder – more than just a page builder v4.1.1
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 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 3.22.0-dev1 4.0.0-beta3 3.22.0-dev2 4.0.0-beta4 3.22.0-dev3 4.0.0-beta5 3.22.0-dev4 4.0.0-dev1 3.22.0-dev5 4.0.0-dev2 3.22.0-dev6 4.0.0-dev3 3.22.1 4.0.0-dev4 3.22.2 4.0.0-dev5 3.22.3 4.0.1 3.23.0 4.0.2 3.23.0-beta1 3.23.0-beta2 3.23.0-beta3 3.23.0-beta4 3.23.0-beta5 3.23.0-beta6 3.23.0-dev1 3.23.0-dev2 3.23.0-dev3 3.23.0-dev4 3.23.0-dev5 3.23.0-dev6 3.23.1 3.23.2 3.23.3 3.23.4 3.24.0 3.24.0-beta1 3.24.0-beta2 3.24.0-beta3 3.24.0-dev1 3.24.0-dev2 3.24.0-dev3 3.24.1 3.24.2 3.24.3 3.24.4 3.24.5 3.24.6 3.24.7 3.24.8 3.25.0 3.25.0-beta1 3.25.0-beta2 3.25.0-beta3 3.25.0-dev1 3.25.0-dev2 3.25.0-dev3 3.25.1 3.25.10 3.25.11 3.25.2 3.25.3 3.25.4 3.25.5 3.25.6 3.25.7 3.25.8 3.25.9 3.26.0 3.26.0-beta1 3.26.0-beta2 3.26.0-beta3 3.26.0-beta4 3.26.0-beta5 3.26.0-dev1 3.26.0-dev2 3.26.0-dev3 3.26.0-dev4 3.26.0-dev5 3.26.1 3.26.2 3.26.3 3.26.4 3.26.5 3.27.0 3.27.0-beta1 3.27.0-beta2 3.27.0-dev1 3.27.0-dev2 3.27.1 3.27.2 3.27.3 3.27.4 3.27.5 3.27.6 3.27.7 3.28.0 3.28.0-beta1 3.28.0-beta2 3.28.0-beta3 3.28.0-dev1 3.28.0-dev2 3.28.0-dev3 3.28.1 3.28.2 3.28.3 3.28.4 3.29.0 3.29.0-beta1 trunk 3.29.0-beta2 3.0.0 3.29.0-beta3 3.0.1 3.29.0-beta4 3.0.10 3.29.0-dev1 3.0.11 3.29.0-dev2 3.0.12 3.29.0-dev3 3.0.13 3.29.0-dev4 3.0.14 3.29.1 3.0.15 3.29.2 3.0.16 3.3.0 3.0.2 3.3.1 3.0.3 3.30.0 3.0.4 3.30.0-beta1 3.0.5 3.30.0-beta2 3.0.6 3.30.0-beta3 3.0.7 3.30.0-dev1 3.0.8 3.30.0-dev2 3.0.8.1 3.30.0-dev3 3.0.9 3.30.1 3.1.0 3.30.2 3.1.0-beta1 3.30.3 3.1.0-beta2 3.30.4 3.1.0-beta3 3.31.0 3.1.0-beta4 3.31.0-beta1 3.1.0-dev1 3.31.0-beta2 3.1.0-dev2 3.31.0-dev1 3.1.0-dev3 3.31.0-dev2 3.1.1 3.31.1 3.1.2 3.31.2 3.1.3 3.31.3 3.1.4 3.31.4 3.10.0 3.31.5 3.10.0-dev1 3.32.0 3.10.1 3.32.0-beta1 3.10.2 3.32.0-beta2 3.11.0 3.32.0-beta3 3.11.0-beta1 3.32.0-dev1 3.11.0-beta2 3.32.0-dev2 3.11.0-beta3 3.32.0-dev3 3.11.0-dev1 3.32.1 3.11.0-dev2 3.32.2 3.11.0-dev3 3.32.3 3.11.1 3.32.4 3.11.2 3.32.5 3.11.3 3.33.0 3.11.4 3.33.0-beta1 3.11.5 3.33.0-beta2 3.12.0 3.33.0-beta3 3.12.1 3.33.0-beta4 3.12.2 3.33.0-dev1 3.13.0 3.33.0-dev2 3.13.0-beta1 3.33.0-dev3 3.13.0-beta2 3.33.0-dev4 3.13.0-beta3 3.33.1 3.13.0-dev3 3.33.2 3.13.0-dev4 3.33.3 3.13.1 3.33.4 3.13.2 3.33.5 3.13.3 3.33.6 3.13.4 3.34.0 3.14.0 3.34.0-beta1 3.14.0-beta1 3.34.0-beta2 3.14.0-beta2 3.34.0-beta3 3.14.0-beta3 3.34.0-dev1 3.14.0-beta4 3.34.0-dev2 3.14.0-beta5 3.34.1 3.14.1 3.34.2 3.15.0 3.34.3 3.15.1 3.34.4 3.15.2 3.35.0 3.15.3 3.35.0-beta1 3.16.0 3.35.0-beta2 3.16.0-beta3 3.35.0-beta3 3.16.0-beta4 3.35.0-beta4 3.16.0-dev1 3.35.0-dev1 3.16.0-dev2 3.35.0-dev2 3.16.1 3.35.0-dev3 3.16.2 3.35.0-dev4 3.16.3 3.35.1 3.16.4 3.35.2 3.16.5 3.35.3 3.16.6 3.35.4 3.17.0 3.35.5 3.17.0-dev2 3.35.6 3.17.0-dev3 3.35.7 3.17.0-dev4 3.35.8 3.17.1 3.35.9 3.17.2 3.4.0 3.17.3 3.4.0-dev7 3.18.0 3.4.0-dev8 3.18.0-beta1 3.4.0-dev9 3.18.0-beta2 3.4.1 3.18.0-beta3 3.4.2 3.18.0-beta4 3.4.3 3.18.0-dev1 3.4.4 3.18.1 3.4.5 3.18.2 3.4.6 3.18.3 3.4.7 3.19.0 3.4.8 3.19.0-beta1 3.5.0 3.19.0-beta2 3.5.0-beta1 3.19.0-beta3 3.5.0-beta2 3.19.0-beta4 3.5.0-beta3 3.19.0-beta5 3.5.0-beta4 3.19.0-beta6 3.5.0-beta5 3.19.0-dev1 3.5.0-beta7 3.19.0-dev2 3.5.0-beta8 3.19.0-dev3 3.5.0-dev8 3.19.0-dev4 3.5.0-dev9 3.19.0-dev5 3.5.1 3.19.0-dev6 3.5.2 3.19.1 3.5.3 3.19.2 3.5.4 3.19.3 3.5.5 3.19.4 3.5.6 3.2.0 3.6.0 3.2.1 3.6.0-beta1 3.2.2 3.6.0-beta2 3.2.3 3.6.0-beta3 3.2.4 3.6.0-beta4 3.2.5 3.6.0-beta5 3.20.0 3.6.0-dev1 3.20.0-beta1 3.6.0-dev10 3.20.0-beta2 3.6.1 3.20.0-beta3 3.6.2 3.20.0-beta4 3.6.3 3.20.0-dev1 3.6.4 3.20.0-dev2 3.6.5 3.20.0-dev3 3.6.6 3.20.0-dev4 3.6.7 3.20.1 3.6.8 3.20.2 3.7.0 3.20.3 3.7.0-beta1 3.20.4 3.7.0-beta2 3.21.0 3.7.0-beta3 3.21.0-beta1 3.7.0-beta4 3.21.0-beta2 3.7.0-dev1 3.21.0-beta3 3.7.1 3.21.0-dev1 3.7.2 3.21.0-dev2 3.7.3 3.21.0-dev3 3.7.4 3.21.1 3.7.5 3.21.2 3.7.6 3.21.3 3.7.7 3.21.4 3.7.8 3.21.5 3.8.0 3.21.6 3.8.0-beta1 3.21.7 3.8.0-beta2 3.21.8 3.8.0-beta3 3.22.0 3.8.1 3.22.0-beta1 3.9.0 3.22.0-beta2 3.9.1 3.22.0-beta3 3.9.2 3.22.0-beta4 4.0.0 3.22.0-beta5 4.0.0-beta1 3.22.0-beta6 4.0.0-beta2
elementor / includes / api.php
elementor / includes Last commit date
admin-templates 1 year ago base 2 weeks ago controls 4 months ago editor-templates 2 weeks ago elements 2 weeks ago interfaces 1 year ago libraries 1 year ago managers 2 weeks ago settings 2 months ago template-library 1 week ago widgets 2 weeks ago api.php 2 weeks ago autoloader.php 7 months ago beta-testers.php 3 years ago compatibility.php 1 year ago conditions.php 3 years ago db.php 4 months ago editor-assets-api.php 2 months ago embed.php 1 year ago fonts.php 1 year ago frontend.php 1 month ago heartbeat.php 3 years ago maintenance-mode.php 7 months ago maintenance.php 1 year ago plugin.php 1 week ago preview.php 2 weeks ago rollback.php 4 months ago shapes.php 9 months ago stylesheet.php 8 months ago tracker.php 6 months ago user-data.php 7 months ago user.php 5 months ago utils.php 2 weeks ago
api.php
371 lines
1 <?php
2 namespace Elementor;
3
4 use Elementor\Core\Common\Modules\Connect\Apps\Library;
5
6 if ( ! defined( 'ABSPATH' ) ) {
7 exit; // Exit if accessed directly.
8 }
9
10 /**
11 * Elementor API.
12 *
13 * Elementor API handler class is responsible for communicating with Elementor
14 * remote servers retrieving templates data and to send uninstall feedback.
15 *
16 * @since 1.0.0
17 */
18 class Api {
19
20 /**
21 * Elementor library option key.
22 */
23 const LIBRARY_OPTION_KEY = 'elementor_remote_info_library';
24
25 /**
26 * Elementor feed option key.
27 */
28 const FEED_OPTION_KEY = 'elementor_remote_info_feed_data';
29
30 const TRANSIENT_KEY_PREFIX = 'elementor_remote_info_api_data_';
31
32 /**
33 * API info URL.
34 *
35 * Holds the URL of the info API.
36 *
37 * @access public
38 * @static
39 *
40 * @var string API info URL. (v2 excludes the Library info)
41 */
42 public static $api_info_url = 'https://my.elementor.com/api/v2/info/';
43
44 /**
45 * API feedback URL.
46 *
47 * Holds the URL of the feedback API.
48 *
49 * @access private
50 * @static
51 *
52 * @var string API feedback URL.
53 */
54 private static $api_feedback_url = 'https://my.elementor.com/api/v1/feedback/';
55
56 private static $api_library_info_url = 'https://my.elementor.com/api/v1/templates/info/';
57
58 private static function get_info_data( $force_update = false, $additional_status = false ) {
59 $cache_key = self::TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION;
60
61 $info_data = get_transient( $cache_key );
62
63 if ( $force_update || empty( $info_data ) ) {
64 $timeout = ( $force_update ) ? 25 : 8;
65
66 $body_request = [
67 // Which API version is used.
68 'api_version' => ELEMENTOR_VERSION,
69 // Which language to return.
70 'site_lang' => get_bloginfo( 'language' ),
71 ];
72
73 $site_key = self::get_site_key();
74 if ( ! empty( $site_key ) ) {
75 $body_request['site_key'] = $site_key;
76 }
77
78 if ( ! empty( $additional_status ) ) {
79 $body_request['status'] = $additional_status;
80 $timeout = 3;
81 }
82
83 $response = wp_remote_get( self::$api_info_url, [
84 'timeout' => $timeout,
85 'body' => $body_request,
86 ] );
87
88 if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
89 set_transient( $cache_key, [ 'last_error' => gmdate( 'c' ) ], 2 * HOUR_IN_SECONDS );
90
91 return false;
92 }
93
94 $info_data = json_decode( wp_remote_retrieve_body( $response ), true );
95
96 if ( empty( $info_data ) || ! is_array( $info_data ) ) {
97 set_transient( $cache_key, [ 'last_error' => gmdate( 'c' ) ], 2 * HOUR_IN_SECONDS );
98
99 return false;
100 }
101
102 if ( isset( $info_data['library'] ) ) {
103 unset( $info_data['library'] );
104 }
105
106 if ( isset( $info_data['feed'] ) ) {
107 update_option( self::FEED_OPTION_KEY, $info_data['feed'], 'no' );
108
109 unset( $info_data['feed'] );
110 }
111
112 set_transient( $cache_key, $info_data, 12 * HOUR_IN_SECONDS );
113 }
114
115 return $info_data;
116 }
117
118 public static function get_site_key() {
119 if ( null === Plugin::$instance->common ) {
120 return get_option( Library::OPTION_CONNECT_SITE_KEY );
121 }
122
123 /** @var Library $library */
124 $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' );
125
126 if ( ! $library || ! method_exists( $library, 'get_site_key' ) ) {
127 return false;
128 }
129
130 return $library->get_site_key();
131 }
132
133 /**
134 * Get upgrade notice.
135 *
136 * Retrieve the upgrade notice if one exists, or false otherwise.
137 *
138 * @since 1.0.0
139 * @access public
140 * @static
141 *
142 * @return array|false Upgrade notice, or false none exist.
143 */
144 public static function get_upgrade_notice() {
145 $data = self::get_info_data();
146
147 if ( empty( $data['upgrade_notice'] ) ) {
148 return false;
149 }
150
151 return $data['upgrade_notice'];
152 }
153
154 public static function get_admin_notice() {
155 $data = self::get_info_data();
156 if ( empty( $data['admin_notice'] ) ) {
157 return false;
158 }
159 return $data['admin_notice'];
160 }
161
162 public static function get_canary_deployment_info( $force = false ) {
163 $data = self::get_info_data( $force );
164
165 if ( empty( $data['canary_deployment'] ) ) {
166 return false;
167 }
168
169 return $data['canary_deployment'];
170 }
171
172 public static function get_promotion_widgets() {
173 $data = self::get_info_data();
174
175 if ( ! isset( $data['pro_widgets'] ) ) {
176 $data['pro_widgets'] = [];
177 }
178
179 return $data['pro_widgets'];
180 }
181
182 /**
183 * Get templates data.
184 *
185 * Retrieve the templates data from a remote server.
186 *
187 * @since 2.0.0
188 * @access public
189 * @static
190 *
191 * @param bool $force_update Optional. Whether to force the data update or
192 * not. Default is false.
193 *
194 * @return array The templates' data.
195 */
196 public static function get_library_data( bool $force_update = false ): array {
197 /**
198 * Filters the body of the request to get library templates data.
199 *
200 * @param-out array $body_request The body of the request.
201 */
202 $body_request = apply_filters( 'elementor/remote/library/templates/request/body', [] );
203
204 $site_key = self::get_site_key();
205 if ( ! empty( $site_key ) ) {
206 $body_request['site_key'] = $site_key;
207 }
208
209 /**
210 * Filters the URL to get library templates data.
211 *
212 * @param-out string $url The URL to get library templates data.
213 */
214 $url = apply_filters( 'elementor/remote/library/templates/request/url', self::$api_library_info_url );
215
216 $response = wp_remote_get( $url, [
217 'timeout' => 25,
218 'body' => $body_request,
219 ] );
220
221 if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
222 return [];
223 }
224
225 $library_data = json_decode( wp_remote_retrieve_body( $response ), true );
226
227 /**
228 * Filters the library data to allow 3rd party extending the response data.
229 *
230 * @since 3.32.2
231 * @param-out array $library_data an array of templates data.
232 */
233 $library_data = apply_filters( 'elementor/remote/library/data', $library_data );
234
235 if ( empty( $library_data ) || ! is_array( $library_data ) ) {
236 return [];
237 }
238
239 // the following update & get are a temporary measure, to allow 3rd party plugins inject more templates:
240 update_option( self::LIBRARY_OPTION_KEY, $library_data, 'no' );
241
242 return get_option( self::LIBRARY_OPTION_KEY, $library_data );
243 }
244
245 /**
246 * Get feed data.
247 *
248 * Retrieve the feed info data from remote elementor server.
249 *
250 * @since 1.9.0
251 * @access public
252 * @static
253 *
254 * @param bool $force_update Optional. Whether to force the data update or
255 * not. Default is false.
256 *
257 * @return array Feed data.
258 */
259 public static function get_feed_data( $force_update = false ) {
260 self::get_info_data( $force_update );
261
262 $feed = get_option( self::FEED_OPTION_KEY );
263
264 if ( empty( $feed ) ) {
265 return [];
266 }
267
268 return $feed;
269 }
270
271 public static function get_deactivation_data() {
272 $data = self::get_info_data( true, 'deactivated' );
273
274 if ( empty( $data['deactivate_data'] ) ) {
275 return false;
276 }
277
278 return $data['deactivate_data'];
279 }
280
281 public static function get_uninstalled_data() {
282 $data = self::get_info_data( true, 'uninstalled' );
283
284 if ( empty( $data['uninstall_data'] ) ) {
285 return false;
286 }
287
288 return $data['uninstall_data'];
289 }
290
291 /**
292 * Get template content.
293 *
294 * Retrieve the templates content received from a remote server.
295 *
296 * @since 1.0.0
297 * @access public
298 * @static
299 *
300 * @param int $template_id The template ID.
301 *
302 * @return object|\WP_Error The template content.
303 */
304 public static function get_template_content( $template_id ) {
305 /** @var Library $library */
306 $library = Plugin::$instance->common->get_component( 'connect' )->get_app( 'library' );
307
308 return $library->get_template_content( $template_id );
309 }
310
311 /**
312 * Send Feedback.
313 *
314 * Fires a request to Elementor server with the feedback data.
315 *
316 * @since 1.0.0
317 * @access public
318 * @static
319 *
320 * @param string $feedback_key Feedback key.
321 * @param string $feedback_text Feedback text.
322 *
323 * @return array The response of the request.
324 */
325 public static function send_feedback( $feedback_key, $feedback_text ) {
326 return wp_remote_post( self::$api_feedback_url, [
327 'timeout' => 30,
328 'body' => [
329 'api_version' => ELEMENTOR_VERSION,
330 'site_lang' => get_bloginfo( 'language' ),
331 'feedback_key' => $feedback_key,
332 'feedback' => $feedback_text,
333 ],
334 ] );
335 }
336
337 /**
338 * Ajax reset API data.
339 *
340 * Reset Elementor library API data using an ajax call.
341 *
342 * @since 1.0.0
343 * @access public
344 * @static
345 */
346 public static function ajax_reset_api_data() {
347 check_ajax_referer( 'elementor_reset_library', '_nonce' );
348
349 if ( ! current_user_can( 'manage_options' ) ) {
350 wp_send_json_error( 'Permission denied' );
351 }
352
353 self::get_info_data( true );
354
355 wp_send_json_success();
356 }
357
358 /**
359 * Init.
360 *
361 * Initialize Elementor API.
362 *
363 * @since 1.0.0
364 * @access public
365 * @static
366 */
367 public static function init() {
368 add_action( 'wp_ajax_elementor_reset_library', [ __CLASS__, 'ajax_reset_api_data' ] );
369 }
370 }
371