B VP?B V`?B Vp?`F V$E V>T$`R^G V`E V>T$R^G VE V-.P$0RC V+G V`PB V$HEE VdF Vp#]ЎE VPP C V<C V+`F V#B V*PB VP#PENG VPPBNG V`BNG VpBP C V<`G VPB V"XENG VPBP C V<PB V"`EE VdF Vp" ]ЎE V PP C V0<C V0@C V@+ B VP9PB V!hENG VPBE Vd@E VR ݠ!`q^ЎE V``NG VpBE Vd@E VR 0!p^ЎE VpP C V<`1D VP:`G VPB V EC V PtP C V< C VC V@+PB V@ ENG VPBC V0 `tE V R`C V p8D VptP C V<D VB V@*OF V^G VF Vp@* VE V  pNG VPBC V<E V-.pE VdF Vp0]ЎE V0PNG V`BP C V@<`G V@PC V` F V`,G VPB VENG VPPBP C V<C V"C V,B V *`F V0B V@*PB VENG VPPBNG V`BNG VpBP C V<`G V B V9PB VPENG VPBE Vd@E V ^ЎE V`NG VpBE Vd@E V^ЎE VP C V<`1D V:`G VPB V 0EC V0PtP C V0< C V0@C V@@+PB V8ENG VPBC V`tE VP@R`C VP`p8D V`ptP C Vp<D VpB V@*OF V^G VE V_=XpNG VPBC V<PC V F V,G V*/ public function export_template( $template_id ) { return new \WP_Error( 'invalid_request', 'Cannot export template from a remote source' ); } /** * Get remote template data. * * Retrieve the data of a single remote template from Elementor.com servers. * * @since 1.5.0 * @access public * * @param array $args Custom template arguments. * @param string $context Optional. The context. Default is `display`. * * @return array|\WP_Error Remote Template data. */ public function get_data( array $args, $context = 'display' ) { $data = Api::get_template_content( $args['template_id'] ); if ( is_wp_error( $data ) ) { return $data; } // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads. Plugin::$instance->uploads_manager->set_elementor_upload_state( true ); // BC. $data = (array) $data; $data['content'] = $this->replace_elements_ids( $data['content'] ); $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' ); $post_id = $args['editor_post_id']; $document = Plugin::$instance->documents->get( $post_id ); if ( $document ) { $data['content'] = $document->get_elements_raw_data( $data['content'], true ); } // After the upload complete, set the elementor upload state back to false Plugin::$instance->uploads_manager->set_elementor_upload_state( false ); return $data; } /** * Get templates data from a transient or from a remote request. * In any of the following 2 conditions, the remote request will be triggered: * 1. Force update - "$force_update = true" parameter was passed. * 2. The data saved in the transient is empty or not exist. * * @param bool $force_update * @return array */ protected function get_templates_data( bool $force_update ): array { $templates_data_cache_key = static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION; $experiments_manager = Plugin::$instance->experiments; $editor_layout_type = $experiments_manager->is_feature_active( 'container' ) ? 'container_flexbox' : ''; if ( $force_update ) { return $this->get_templates( $editor_layout_type ); } $templates_data = get_transient( $templates_data_cache_key ); if ( empty( $templates_data ) ) { return $this->get_templates( $editor_layout_type ); } return $templates_data; } /** * Get the templates from a remote server and set a transient. * * @param string $editor_layout_type * @return array */ protected function get_templates( string $editor_layout_type ): array { $templates_data_cache_key = static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION; $templates_data = $this->get_templates_remotely( $editor_layout_type ); if ( empty( $templates_data ) ) { return []; } set_transient( $templates_data_cache_key, $templates_data, 12 * HOUR_IN_SECONDS ); return $templates_data; } /** * Fetch templates from the remote server. * * @param string $editor_layout_type * @return array|false */ protected function get_templates_remotely( string $editor_layout_type ) { $response = wp_remote_get( static::API_TEMPLATES_URL, [ 'body' => $this->get_templates_body_args( $editor_layout_type ), ] ); if ( is_wp_error( $response ) || 200 !== (int) wp_remote_retrieve_response_code( $response ) ) { return false; } $templates_data = json_decode( wp_remote_retrieve_body( $response ), true ); if ( empty( $templates_data ) || ! is_array( $templates_data ) ) { return []; } return $templates_data; } /** * Prepare the body arguments for the remote request. * * @param string $editor_layout_type * * @return array */ protected function get_templates_body_args( string $editor_layout_type ): array { return [ 'plugin_version' => ELEMENTOR_VERSION, 'editor_layout_type' => $editor_layout_type, ]; } /** * @since 2.2.0 * @access private */ protected function prepare_template( array $template_data ) { $favorite_templates = $this->get_user_meta( 'favorites' ); // BC: Support legacy APIs that don't have access tiers. if ( isset( $template_data['access_tier'] ) ) { $access_tier = $template_data['access_tier']; } else { $access_tier = 0 === $template_data['access_level'] ? ConnectModule::ACCESS_TIER_FREE : ConnectModule::ACCESS_TIER_ESSENTIAL; } return [ 'template_id' => $template_data['id'], 'source' => $this->get_id(), 'type' => $template_data['type'], 'subtype' => $template_data['subtype'], 'title' => $template_data['title'], 'thumbnail' => $template_data['thumbnail'], 'date' => $template_data['tmpl_created'], 'author' => $template_data['author'], 'tags' => json_decode( $template_data['tags'] ), 'isPro' => ( '1' === $template_data['is_pro'] ), 'accessLevel' => $template_data['access_level'], 'accessTier' => $access_tier, 'popularityIndex' => (int) $template_data['popularity_index'], 'trendIndex' => (int) $template_data['trend_index'], 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ), 'url' => $template_data['url'], 'favorite' => ! empty( $favorite_templates[ $template_data['id'] ] ), ]; } public function clear_cache() { delete_transient( static::TEMPLATES_DATA_TRANSIENT_KEY_PREFIX . ELEMENTOR_VERSION ); } }