PluginProbe
Elementor Website Builder – more than just a page builder / 4.0.3
Elementor Website Builder – more than just a page builder v4.0.3
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
elementor / app / modules / import-export-customization / runners / export / templates.php

templates.php in Elementor Website Builder – more than just a page builder 4.0.3, at app/modules/import-export-customization/runners/export/templates.php

106 lines 2.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\App\Modules\ImportExportCustomization\Runners\Export;
4
5 use Elementor\Core\Base\Document;
6 use Elementor\Plugin;
7 use Elementor\TemplateLibrary\Source_Local;
8 use Elementor\Utils;
9 use Elementor\Modules\Library\Documents\Library_Document;
10
11 class Templates extends Export_Runner_Base {
12
13 public static function get_name(): string {
14 return 'templates';
15 }
16
17 public function should_export( array $data ) {
18 return (
19 Utils::has_pro() &&
20 isset( $data['include'] ) &&
21 in_array( 'templates', $data['include'], true )
22 );
23 }
24
25 public function export( array $data ) {
26 $customization = $data['customization']['templates'] ?? null;
27
28 if ( $customization ) {
29 return $this->export_with_customization( $data, $customization );
30 }
31
32 return $this->export_all( $data );
33 }
34
35 private function export_with_customization( array $data, array $customization ) {
36 $result = apply_filters( 'elementor/import-export-customization/export/templates/customization', null, $data, $customization, $this );
37
38 if ( is_array( $result ) ) {
39 return $result;
40 }
41
42 return $this->export_all( $data );
43 }
44
45 private function export_all( array $data ) {
46 $template_types = array_values( Source_Local::get_template_types() );
47
48 return $this->export_templates_by_types( $template_types, $data );
49 }
50
51 public function export_templates_by_types( array $template_types, array $data ) {
52 $templates_manifest_data = [];
53 $files = [];
54
55 if ( ! empty( $template_types ) ) {
56 $query_args = [
57 'post_type' => Source_Local::CPT,
58 'post_status' => 'publish',
59 'posts_per_page' => -1,
60 'meta_query' => [
61 [
62 'key' => Document::TYPE_META_KEY,
63 'value' => $template_types,
64 ],
65 ],
66 ];
67
68 $templates_query = new \WP_Query( $query_args );
69
70 foreach ( $templates_query->posts as $template_post ) {
71 $template_id = $template_post->ID;
72
73 $template_document = Plugin::$instance->documents->get( $template_id );
74
75 $templates_manifest_data[ $template_id ] = $template_document->get_export_summary();
76
77 $files[] = [
78 'path' => 'templates/' . $template_id,
79 'data' => $template_document->get_export_data(),
80 ];
81 }
82 }
83
84 $manifest_data['templates'] = $templates_manifest_data;
85
86 $export_data = [
87 'files' => $files,
88 'manifest' => [
89 $manifest_data,
90 ],
91 ];
92
93 /**
94 * Filter the templates export data to allow adding additional data.
95 *
96 * @param array $export_data The export data structure with 'files' and 'manifest' keys.
97 * @param array $data The full export data.
98 * @param array|null $customization The customization settings for templates.
99 */
100 $customization = $data['customization']['templates'] ?? null;
101 $export_data = apply_filters( 'elementor/import-export-customization/export/templates_data', $export_data, $data, $customization );
102
103 return $export_data;
104 }
105 }
106