PluginProbe
Elementor Website Builder – more than just a page builder / 3.27.4
Elementor Website Builder – more than just a page builder v3.27.4
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 +33 -4 4.2.23.27.4 View file →
@@ -22,8 +22,18 @@
22 22 const API_TEMPLATES_URL = 'https://my.elementor.com/api/connect/v1/library/templates';
23 23
24 24 const TEMPLATES_DATA_TRANSIENT_KEY_PREFIX = 'elementor_remote_templates_data_';
25 25
26 + public function __construct() {
27 + parent::__construct();
28 +
29 + $this->add_actions();
30 + }
31 +
32 + public function add_actions() {
33 + add_action( 'elementor/experiments/feature-state-change/container', [ $this, 'clear_cache' ], 10, 0 );
34 + }
35 +
26 36 /**
27 37 * Get remote template ID.
28 38 *
29 39 * Retrieve the remote template ID.
@@ -223,13 +233,25 @@
223 233 *
224 234 * @param bool $force_update
225 235 * @return array
226 236 */
227 - protected function get_templates_data( bool $force_update ): array {
237 + protected function get_templates_data( bool $force_update ) : array {
238 + $templates_data_cache_key = static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION;
239 +
228 240 $experiments_manager = Plugin::$instance->experiments;
229 241 $editor_layout_type = $experiments_manager->is_feature_active( 'container' ) ? 'container_flexbox' : '';
230 242
231 - return $this->get_templates( $editor_layout_type );
243 + if ( $force_update ) {
244 + return $this->get_templates( $editor_layout_type );
245 + }
246 +
247 + $templates_data = get_transient( $templates_data_cache_key );
248 +
249 + if ( empty( $templates_data ) ) {
250 + return $this->get_templates( $editor_layout_type );
251 + }
252 +
253 + return $templates_data;
232 254 }
233 255
234 256 /**
235 257 * Get the templates from a remote server and set a transient.
@@ -237,11 +259,19 @@
237 259 * @param string $editor_layout_type
238 260 * @return array
239 261 */
240 262 protected function get_templates( string $editor_layout_type ): array {
263 + $templates_data_cache_key = static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION;
264 +
241 265 $templates_data = $this->get_templates_remotely( $editor_layout_type );
242 266
243 - return empty( $templates_data ) ? [] : $templates_data;
267 + if ( empty( $templates_data ) ) {
268 + return [];
269 + }
270 +
271 + set_transient( $templates_data_cache_key, $templates_data, 12 * HOUR_IN_SECONDS );
272 +
273 + return $templates_data;
244 274 }
245 275
246 276 /**
247 277 * Fetch templates from the remote server.
@@ -268,9 +298,8 @@
268 298 }
269 299
270 300 /**
271 301 * Prepare the body arguments for the remote request.
272 - *
273 302 * @param string $editor_layout_type
274 303 *
275 304 * @return array
276 305 */