PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.3.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.3.3
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/Importer/Utils/GutenbergHelper.php +36 -29 3.1.13.3.3 View file →
@@ -33,9 +33,12 @@
33 33 */
34 34 public function prepare( $template_json, $template_settings, $extra_content = [], $request_params = [] ) {
35 35 $this->template_settings = $template_settings;
36 36 $this->post_id = $this->map_post_ids[ $template_settings['post_id'] ];
37 - $this->wp_importer = new WPImport( null, ['fetch_attachments' => true] );
37 + $this->wp_importer = new WPImport( null, [
38 + 'session_id' => $this->session_id,
39 + 'fetch_attachments' => true,
40 + ] );
38 41
39 42 $parsed_blocks = parse_blocks( $template_json['content'] );
40 43 if ( ! empty( $extra_content ) ) {
41 44 $this->prepare_form_data( $extra_content, $template_settings );
@@ -106,9 +109,9 @@
106 109
107 110 if ( ! empty( $block['innerBlocks'] ) ) {
108 111 $this->replace( $block['innerBlocks'], $request_params );
109 112 }
110 - else if(!empty($request_params['logo']) && isset($request_params['logo_size']) && $request_params['logo_size'] && $block['blockName'] === "essential-blocks/advanced-image" && $block["attrs"]["imgSource"] === "site-logo"){
113 + else if(!empty($request_params['logo']['id']) && isset($request_params['logo_size']) && $request_params['logo_size'] && $block['blockName'] === "essential-blocks/advanced-image" && $block["attrs"]["imgSource"] === "site-logo"){
111 114 $block["attrs"]["widthRange"] = $request_params['logo_size'];
112 115 unset($block["attrs"]["widthUnit"]);
113 116 if (isset($block['attrs']['blockMeta']['desktop']) && is_string($block['attrs']['blockMeta']['desktop'])) {
114 117 $meta = $block['attrs']['blockMeta']['desktop'];
@@ -135,12 +138,19 @@
135 138 $changed = false;
136 139 foreach ( $blocks as &$block ) {
137 140 $this->sse_log('query', 'Finalizing archive settings, just a moment...', 1, 'eventLog');
138 141
139 - if ( isset( $block['attrs']['id'] ) && $block['attrs']['id'] === $this->imported_data['archive_settings']['archive_id'] ) {
140 - $changed = true;
141 - $block['attrs']['id'] = $this->imported_data['archive_settings']['page_id'];
142 - $block['attrs']['url'] = get_the_permalink( $this->imported_data['archive_settings']['page_id'] );
142 + if (isset($block['attrs']['id'])) {
143 + $blockId = $block['attrs']['id'];
144 + $archiveSettings = $this->imported_data['archive_settings'];
145 +
146 + $archiveIds = $archiveSettings[$blockId] ?? false;
147 +
148 + if ($archiveIds) {
149 + $block['attrs']['id'] = $archiveIds['page_id'];
150 + $block['attrs']['url'] = get_the_permalink($archiveIds['page_id']);
151 + $changed = true;
152 + }
143 153 }
144 154 }
145 155 if ( $changed ) {
146 156 wp_update_post( [
@@ -344,8 +354,27 @@
344 354 if ($post_data === null) {
345 355 continue;
346 356 }
347 357
358 + foreach ($sizes as $key => $size) {
359 + if ($base_url == $size) {
360 + unset($sizes[$key]);
361 + continue;
362 + }
363 +
364 + // $size url string; get width height from the image url
365 + preg_match('/-(\d+)x(\d+)\.[a-zA-Z]+$/', $size, $matches);
366 + if (isset($matches[1]) && isset($matches[2])) {
367 + $sizes[$key] = [
368 + 'file' => basename($size),
369 + 'width' => $matches[1],
370 + 'height' => $matches[2]
371 + ];
372 + } else {
373 + unset($sizes[$key]);
374 + }
375 + }
376 +
348 377 // Check if the attachment already exists
349 378 $attachment_id = $this->wp_importer->process_attachment($post_data, $base_url, $sizes);
350 379 // If there was an error, handle it here
351 380 if (is_wp_error($attachment_id)) {
@@ -357,31 +386,9 @@
357 386 }
358 387 }
359 388
360 389 private function prepare_post_data($post_id, $image_url) {
361 - $filetype = wp_check_filetype(basename($image_url));
362 - if (!$filetype['type']) {
363 - $this->sse_log('prepare', 'Error: Unable to determine the file type.', -1, 'eventLog');
364 - return null;
365 - }
366 -
367 - $post_data = array(
368 - 'post_title' => basename($image_url),
369 - 'post_content' => '',
370 - 'post_status' => 'inherit',
371 - 'post_mime_type' => $filetype['type'],
372 - 'guid' => $image_url,
373 - 'post_parent' => $post_id, // Set the parent post
374 - );
375 -
376 - if (preg_match('%wp-content/uploads/([0-9]{4}/[0-9]{2})%', $image_url, $matches)) {
377 - $post_data['upload_date'] = $matches[1];
378 - }
379 - else{
380 - $post_data['upload_date'] = date('Y/m');
381 - }
382 -
383 - return $post_data;
390 + return Utils::prepare_post_data($image_url, $post_id, [$this, 'sse_log']);
384 391 }
385 392
386 393 public function sse_log( $type, $message, $progress = 1, $action = 'updateLog', $status = null ) {
387 394 if ($this->shouldLog) {