PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.4.5
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.4.5
3.8.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 All 112 releases
← All changes | includes/Core/Importer/Runners/Templates.php +39 -38 3.1.10 → 3.4.5 View file →
@@ -5,9 +5,8 @@
5 5 use Exception;
6 6 use Templately\Builder\PageTemplates;
7 7 use Templately\Builder\Types\BaseTemplate;
8 8 use Templately\Core\Importer\Utils\Utils;
9 -use Templately\Core\Importer\WPImport;
10 9 use Templately\Utils\Helper;
11 10
12 11 class Templates extends BaseRunner {
13 12 protected $imported_types = [];
@@ -38,40 +37,24 @@
38 37 $path = $this->dir_path . 'templates' . DIRECTORY_SEPARATOR;
39 38
40 39 $_extra_pages = [];
41 40
42 - // Get the processed templates from the session data
43 - $processed_templates = $this->origin->get_progress();
44 41
45 - if(empty($processed_templates)){
46 - $this->log( 0 );
47 - $processed_templates = ["__started__"];
48 - $this->origin->update_progress( $processed_templates);
49 - $this->create_page_template();
50 - }
51 -
52 42 $total = count( $templates );
53 43
54 -
55 - foreach ( $templates as $id => $template_settings ) {
56 - // Broadcast Log
57 - // If the template has been processed, skip it
58 - if (in_array($id, $processed_templates)) {
59 - continue;
60 - }
61 -
44 + $results = $this->loop( $templates, function($id, $template_settings, $results ) use( $path, $total ) {
62 45 $template_content = Utils::read_json_file( $path . $id . '.json' );
63 46
64 47 $import = $this->import_template( $id, $template_settings, $template_content );
65 48 if ( $import ) {
66 - $results['succeed'][ $id ] = $import['id'];
67 - $results['template_types'][] = $template_settings['type'];
49 + $results['templates']['succeed'][ $id ] = $import['id'];
50 + $results['templates']['template_types'][] = $template_settings['type'];
68 51
69 52 if ( $template_settings['type'] === 'archive' || $template_settings['type'] === 'product_archive' || $template_settings['type'] === 'course_archive' ) {
70 53 $page_id = $this->create_archive_page( $template_settings, $this->manifest['platform'] );
71 54 if ( $page_id && isset($template_settings['page_settings']['archive_page_id']) ) {
72 55 $archive_page_id = $template_settings['page_settings']['archive_page_id'];
73 - $_extra_pages['archive_settings'][$archive_page_id] = [
56 + $results['archive_settings'][$archive_page_id] = [
74 57 'old_id' => $id,
75 58 'page_id' => $page_id,
76 59 'archive_id' => $archive_page_id
77 60 ];
@@ -76,39 +59,33 @@
76 59 'archive_id' => $archive_page_id
77 60 ];
78 61 }
79 62 }
63 + else if($template_settings['type'] === 'fluent_product_single'){
64 + $this->create_page_template();
65 + }
80 66
81 67 } else {
82 - $results['failed'][ $id ] = $import;
68 + $results['templates']['failed'][ $id ] = $import;
83 69 }
84 70
85 71 // Broadcast Log
86 72 $processed = 0;
87 - array_walk_recursive($results, function($item) use (&$processed) {
73 + $processed_template = array_merge($results['templates']['succeed'] ?? [], $results['templates']['failed'] ?? []);
74 + array_walk_recursive($processed_template, function($item, $key) use (&$processed) {
88 75 $processed++;
89 76 });
90 77 $progress = floor( ( 100 * $processed ) / $total );
91 78 $this->log( $progress );
92 79
93 - $results['__attachments'][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : [];
80 + $results['templates']['__attachments'][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : [];
94 81 // Add the template to the processed templates and update the session data
95 - $processed_templates[] = $id;
96 - $this->origin->update_progress( $processed_templates, array_merge( [ 'templates' => $results ], $_extra_pages ));
97 82
98 - // If it's not the last item, send the SSE message and exit
99 - if( end($templates) !== $template_settings ) {
100 - $this->sse_message( [
101 - 'type' => 'continue',
102 - 'action' => 'continue',
103 - 'i' => $id,
104 - 'results' => __METHOD__ . '::' . __LINE__,
105 - ] );
106 - exit;
107 - }
108 - }
109 83
110 - return array_merge( [ 'templates' => $results ], $_extra_pages );
84 + return $results;
85 + }); // , null, true
86 +
87 + return $results;
111 88 }
112 89
113 90 private function import_template( $id, $template_settings, $template_content ) {
114 91 $type = $template_settings['type'];
@@ -150,8 +127,16 @@
150 127
151 128 $template_content['id'] = $id;
152 129 unset($template_settings['conditions']);
153 130 $template_content['import_settings'] = $template_settings;
131 +
132 + if($this->platform === 'elementor' && $this->is_ai_content($id)){
133 + $template_content['content'] = [];
134 + }
135 + else if($this->platform === 'gutenberg' && $this->is_ai_content($id)){
136 + $template_content['content'] = '';
137 + }
138 +
154 139 $template->import( $template_content );
155 140
156 141 if($template->has_logo($template_content)){
157 142 $this->manifest['templates'][$id]['has_logo'] = true;
@@ -194,8 +179,24 @@
194 179
195 180 if($type === 'product_archive'){
196 181 Utils::update_option( 'woocommerce_shop_page_id', $archive_page );
197 182 }
183 +
184 + if($type === 'course_archive'){
185 + // get page slug from $archive_page id and update learndash_settings_permalinks option to courses.
186 + $post_name = get_post_field( 'post_name', $archive_page );
187 +
188 + if(class_exists('\LearnDash_Settings_Section')){
189 + $section = \LearnDash_Settings_Section::get_section_instance( 'LearnDash_Settings_Section_Permalinks' );
190 + if(!empty($section)){
191 + $section->set_setting('courses', $post_name);
192 + if(function_exists('learndash_setup_rewrite_flush')){
193 + learndash_setup_rewrite_flush();
194 + }
195 + }
196 + }
197 + }
198 +
198 199 return $archive_page;
199 200 } catch ( \Exception $e ) {
200 201 return false;
201 202 }