PluginProbe
Elementor Website Builder – more than just a page builder / 4.3.0-beta3
Elementor Website Builder – more than just a page builder v4.3.0-beta3
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 / modules / default-styles / import-export-customization / runners / import.php

import.php in Elementor Website Builder – more than just a page builder 4.3.0-beta3, at modules/default-styles/import-export-customization/runners/import.php

72 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Modules\DefaultStyles\ImportExportCustomization\Runners;
4
5 use Elementor\App\Modules\ImportExportCustomization\Design_System_Import_Context;
6 use Elementor\App\Modules\ImportExportCustomization\Runners\Import\Import_Runner_Base;
7 use Elementor\App\Modules\ImportExportCustomization\Utils as ImportExportUtils;
8 use Elementor\Modules\AtomicWidgets\Module as Atomic_Widgets_Module;
9 use Elementor\Modules\DefaultStyles\Default_Styles_Repository;
10 use Elementor\Modules\DefaultStyles\ImportExportCustomization\Import_Export_Customization;
11 use Elementor\Plugin;
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 class Import extends Import_Runner_Base {
18 public static function get_name(): string {
19 return 'default-styles';
20 }
21
22 public function should_import( array $data ): bool {
23 $import_context = Design_System_Import_Context::from_data( $data );
24
25 return (
26 $import_context->is_included() &&
27 ! empty( $data['extracted_directory_path'] ) &&
28 $this->is_feature_active()
29 );
30 }
31
32 private function is_feature_active(): bool {
33 return Plugin::$instance->experiments->is_feature_active( Atomic_Widgets_Module::EXPERIMENT_NAME );
34 }
35
36 public function import( array $data, array $imported_data ): array {
37 $kit = Plugin::$instance->kits_manager->get_active_kit();
38 $default_styles_dir = $data['extracted_directory_path'] . '/' . Import_Export_Customization::DIRECTORY_NAME;
39
40 if ( ! $kit || ! is_dir( $default_styles_dir ) ) {
41 return [];
42 }
43
44 $repository = Default_Styles_Repository::make( $kit );
45 $imported_tags = [];
46
47 foreach ( glob( $default_styles_dir . '/*.json' ) as $file_path ) {
48 $tag = basename( $file_path, '.json' );
49
50 if ( ! Default_Styles_Repository::is_allowed_tag( $tag ) ) {
51 continue;
52 }
53
54 $style_data = ImportExportUtils::read_json_file( $file_path );
55
56 if ( ! $style_data ) {
57 continue;
58 }
59
60 if ( ! $repository->put( $tag, $style_data ) ) {
61 continue;
62 }
63
64 $imported_tags[] = $tag;
65 }
66
67 return [
68 'imported' => $imported_tags,
69 ];
70 }
71 }
72