PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.0.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.0.2
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
← All changes | includes/Core/Platform/Gutenberg.php +35 -3 3.1.103.0.2 View file →
@@ -1,9 +1,9 @@
1 1 <?php
2 2 namespace Templately\Core\Platform;
3 3
4 4 use Templately\API\Import;
5 -use Templately\Core\Importer\Utils\Utils;
5 +use Templately\Core\Importer\Utils\GutenbergHelper;
6 6 use Templately\Core\Platform;
7 7 use Templately\Core\Module;
8 8 use Templately\Utils\Helper;
9 9
@@ -134,9 +134,9 @@
134 134 );
135 135 }
136 136
137 137 if($inserted_ID){
138 - $post_data['content'] = Utils::import_and_replace_attachments($post_data['content'], $inserted_ID);
138 + $post_data = $this->process_images($post_data, $inserted_ID);
139 139
140 140 // Update the post content with the processed images
141 141 $updated_post = array(
142 142 'ID' => $inserted_ID,
@@ -159,9 +159,41 @@
159 159 * @param int $postId
160 160 * @return array
161 161 */
162 162 public function insert($data, $postId = 0) {
163 - $data['content'] = Utils::import_and_replace_attachments($data['content'], $postId);
163 + $data = $this->process_images($data, $postId);
164 164 return $data;
165 165 }
166 166
167 + /**
168 + * Inserts a template into the Gutenberg editor.
169 + *
170 + * @param mixed $data
171 + * @param int $postId
172 + * @return array
173 + */
174 + public function process_images($data, $postId = 0) {
175 + // Instantiate GutenbergHelper
176 + $helper = new GutenbergHelper();
177 +
178 + // Organize URLs from the content
179 + $organizedUrls = $helper->parse_images($data['content']);
180 +
181 + // Define template settings
182 + $template_settings = [
183 + 'post_id' => $postId,
184 + '__attachments' => $organizedUrls,
185 + ];
186 +
187 + // Map post IDs and disable logging
188 + $helper->map_post_ids[$postId] = $postId;
189 + $helper->shouldLog = false;
190 +
191 + // Prepare the helper with the data and settings
192 + $helper->prepare($data, $template_settings);
193 +
194 + // Update the content in the data array
195 + $data['content'] = wp_unslash($helper->get_content());
196 +
197 + return $data;
198 + }
167 199 }