PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.0.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.0.0
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Core / Importer / Runners / ExtraContent.php

ExtraContent.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.0.0, at includes/Core/Importer/Runners/ExtraContent.php

93 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Core\Importer\Runners;
4
5 use Exception;
6 use Templately\Core\Importer\Form;
7 use Templately\Core\Importer\Runners\BaseRunner;
8
9 class ExtraContent extends BaseRunner {
10
11 public function get_name(): string {
12 return 'extra-content';
13 }
14
15 public function get_label(): string {
16 return __( 'Extra Contents', 'templately' );
17 }
18
19 public function should_log(): bool {
20 return true;
21 }
22
23 public function get_action(): string {
24 return 'eventLog';
25 }
26
27 public function log_message(): string {
28 return __( 'Importing Forms and Others Extra Contents', 'templately' );
29 }
30
31 public function should_run( $data, $imported_data = [] ): bool {
32 return ! empty( $this->manifest['extra-content'] ) && !empty($data['import_demo_content']);
33 }
34
35 public function import( $data, $imported_data ): array {
36 $extra_content = [];
37 $contents = $this->manifest['extra-content'];
38
39 if( ! empty( $contents ) ) {
40 foreach( $contents as $type => $content ) {
41 switch ( $type ) {
42 case 'form':
43 $import = $this->import_form( $content );
44 $extra_content['form'] = $import;
45 break;
46 case 'data':
47 break;
48 }
49 }
50
51 // $imported_data = array_merge( $imported_data, [ 'extra-content' => $this->extra_content ] );
52 }
53
54
55 return [ 'extra-content' => $extra_content ];
56 }
57
58 private function import_form( $contents ): array {
59 if( ! is_array( $contents ) || empty( $contents ) ) {
60 return [];
61 }
62
63 $result = [];
64
65 $root_path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
66
67 foreach( $contents as $json_id => $plugin_list ) {
68 if( empty( $plugin_list ) ) {
69 continue;
70 }
71
72 foreach ( $plugin_list as $plugin_name => $form_list ) {
73 if( empty( $form_list ) ) {
74 continue;
75 }
76
77 foreach ( $form_list as $form ) {
78 try {
79 $file_path = $root_path . wp_unslash( $form['file_path'] );
80 $import = new Form( $plugin_name, $file_path, $form );
81 $data = $import->run();
82
83 $result[$json_id][ $plugin_name ][ $form['id'] ] = $data;
84 } catch ( Exception $e ) {
85 continue;
86 }
87 }
88 }
89 }
90
91 return $result;
92 }
93 }