get_items(); return $templates[ $template_id ]; } public function request_template_data( $template_id ) { if ( empty( $template_id ) ) { return; } $body = [ 'home_url' => trailingslashit( home_url() ), 'plugin_version' => \ElementsKit_Lite::version(), ]; $query = array_merge([ 'action' => 'get_layout_data', 'layout_id' => $template_id, ], \ElementsKit_Lite::license_data()); $request_url = \ElementsKit_Lite::api_url() . 'layout-manager-api/' . '?' . http_build_query($query); $response = wp_remote_get( $request_url, [ 'timeout' => 30, ] ); return wp_remote_retrieve_body( $response ); } public function get_data( array $args, $context = 'display' ) { $data = $this->request_template_data( $args['template_id'] ); $data = json_decode( $data, true ); if ( empty( $data ) || empty( $data['content'] ) ) { throw new \Exception( __( 'Template does not have any content', 'elementskit-lite' ) ); } $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 = \Elementor\Plugin::instance()->documents->get( $post_id ); if ( $document ) { $data['content'] = $document->get_elements_raw_data( $data['content'], true ); } return $data; } }