PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.0
Elementor Website Builder – more than just a page builder v3.2.0
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 | includes/template-library/sources/remote.php +8 -99 4.1.53.2.0 View file →
@@ -1,9 +1,8 @@
1 1 <?php
2 2 namespace Elementor\TemplateLibrary;
3 3
4 4 use Elementor\Api;
5 -use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
6 5 use Elementor\Plugin;
7 6
8 7 if ( ! defined( 'ABSPATH' ) ) {
9 8 exit; // Exit if accessed directly.
@@ -18,12 +17,8 @@
18 17 * @since 1.0.0
19 18 */
20 19 class Source_Remote extends Source_Base {
21 20
22 - const API_TEMPLATES_URL = 'https://my.elementor.com/api/connect/v1/library/templates';
23 -
24 - const TEMPLATES_DATA_TRANSIENT_KEY_PREFIX = 'elementor_remote_templates_data_';
25 -
26 21 /**
27 22 * Get remote template ID.
28 23 *
29 24 * Retrieve the remote template ID.
@@ -47,9 +42,9 @@
47 42 *
48 43 * @return string The remote template title.
49 44 */
50 45 public function get_title() {
51 - return esc_html__( 'Remote', 'elementor' );
46 + return __( 'Remote', 'elementor' );
52 47 }
53 48
54 49 /**
55 50 * Register remote template data.
@@ -69,21 +64,21 @@
69 64 *
70 65 * @since 1.0.0
71 66 * @access public
72 67 *
73 - * @param array $args Optional. Not used in remote source.
68 + * @param array $args Optional. Nou used in remote source.
74 69 *
75 70 * @return array Remote templates.
76 71 */
77 72 public function get_items( $args = [] ) {
78 - $force_update = ! empty( $args['force_update'] ) && is_bool( $args['force_update'] );
73 + $library_data = Api::get_library_data();
79 74
80 - $templates_data = $this->get_templates_data( $force_update );
81 -
82 75 $templates = [];
83 76
84 - foreach ( $templates_data as $template_data ) {
85 - $templates[] = $this->prepare_template( $template_data );
77 + if ( ! empty( $library_data['templates'] ) ) {
78 + foreach ( $library_data['templates'] as $template_data ) {
79 + $templates[] = $this->prepare_template( $template_data );
80 + }
86 81 }
87 82
88 83 return $templates;
89 84 }
@@ -193,11 +188,8 @@
193 188 if ( is_wp_error( $data ) ) {
194 189 return $data;
195 190 }
196 191
197 - // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads.
198 - Plugin::$instance->uploads_manager->set_elementor_upload_state( true );
199 -
200 192 // BC.
201 193 $data = (array) $data;
202 194
203 195 $data['content'] = $this->replace_elements_ids( $data['content'] );
@@ -208,96 +200,18 @@
208 200 if ( $document ) {
209 201 $data['content'] = $document->get_elements_raw_data( $data['content'], true );
210 202 }
211 203
212 - // After the upload complete, set the elementor upload state back to false
213 - Plugin::$instance->uploads_manager->set_elementor_upload_state( false );
214 -
215 204 return $data;
216 205 }
217 206
218 207 /**
219 - * Get templates data from a transient or from a remote request.
220 - * In any of the following 2 conditions, the remote request will be triggered:
221 - * 1. Force update - "$force_update = true" parameter was passed.
222 - * 2. The data saved in the transient is empty or not exist.
223 - *
224 - * @param bool $force_update
225 - * @return array
226 - */
227 - protected function get_templates_data( bool $force_update ): array {
228 - $experiments_manager = Plugin::$instance->experiments;
229 - $editor_layout_type = $experiments_manager->is_feature_active( 'container' ) ? 'container_flexbox' : '';
230 -
231 - return $this->get_templates( $editor_layout_type );
232 - }
233 -
234 - /**
235 - * Get the templates from a remote server and set a transient.
236 - *
237 - * @param string $editor_layout_type
238 - * @return array
239 - */
240 - protected function get_templates( string $editor_layout_type ): array {
241 - $templates_data = $this->get_templates_remotely( $editor_layout_type );
242 -
243 - return empty( $templates_data ) ? [] : $templates_data;
244 - }
245 -
246 - /**
247 - * Fetch templates from the remote server.
248 - *
249 - * @param string $editor_layout_type
250 - * @return array|false
251 - */
252 - protected function get_templates_remotely( string $editor_layout_type ) {
253 - $response = wp_remote_get( static::API_TEMPLATES_URL, [
254 - 'body' => $this->get_templates_body_args( $editor_layout_type ),
255 - ] );
256 -
257 - if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
258 - return false;
259 - }
260 -
261 - $templates_data = json_decode( wp_remote_retrieve_body( $response ), true );
262 -
263 - if ( empty( $templates_data ) || ! is_array( $templates_data ) ) {
264 - return [];
265 - }
266 -
267 - return $templates_data;
268 - }
269 -
270 - /**
271 - * Prepare the body arguments for the remote request.
272 - *
273 - * @param string $editor_layout_type
274 - *
275 - * @return array
276 - */
277 - protected function get_templates_body_args( string $editor_layout_type ): array {
278 - return [
279 - 'plugin_version' => ELEMENTOR_VERSION,
280 - 'editor_layout_type' => $editor_layout_type,
281 - ];
282 - }
283 -
284 - /**
285 208 * @since 2.2.0
286 209 * @access private
287 210 */
288 - protected function prepare_template( array $template_data ) {
211 + private function prepare_template( array $template_data ) {
289 212 $favorite_templates = $this->get_user_meta( 'favorites' );
290 213
291 - // BC: Support legacy APIs that don't have access tiers.
292 - if ( isset( $template_data['access_tier'] ) ) {
293 - $access_tier = $template_data['access_tier'];
294 - } else {
295 - $access_tier = 0 === $template_data['access_level']
296 - ? ConnectModule::ACCESS_TIER_FREE
297 - : ConnectModule::ACCESS_TIER_ESSENTIAL;
298 - }
299 -
300 214 return [
301 215 'template_id' => $template_data['id'],
302 216 'source' => $this->get_id(),
303 217 'type' => $template_data['type'],
@@ -308,9 +222,8 @@
308 222 'author' => $template_data['author'],
309 223 'tags' => json_decode( $template_data['tags'] ),
310 224 'isPro' => ( '1' === $template_data['is_pro'] ),
311 225 'accessLevel' => $template_data['access_level'],
312 - 'accessTier' => $access_tier,
313 226 'popularityIndex' => (int) $template_data['popularity_index'],
314 227 'trendIndex' => (int) $template_data['trend_index'],
315 228 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ),
316 229 'url' => $template_data['url'],
@@ -315,10 +228,6 @@
315 228 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ),
316 229 'url' => $template_data['url'],
317 230 'favorite' => ! empty( $favorite_templates[ $template_data['id'] ] ),
318 231 ];
319 - }
320 -
321 - public function clear_cache() {
322 - delete_transient( static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION );
323 232 }
324 233 }