| @@ -87,18 +87,8 @@ | ||
| 87 | 87 | * WXR attachment ID |
| 88 | 88 | */ |
| 89 | 89 | private $id; |
| 90 | 90 | |
| 91 | - /** | |
| 92 | - * @var mixed | |
| 93 | - */ | |
| 94 | - private $json; | |
| 95 | - | |
| 96 | - /** | |
| 97 | - * @var string | |
| 98 | - */ | |
| 99 | - private $session_id; | |
| 100 | - | |
| 101 | 91 | // Information to import from WXR file. |
| 102 | 92 | private $version; |
| 103 | 93 | private $authors = []; |
| 104 | 94 | public $posts = []; |
| @@ -119,10 +109,8 @@ | ||
| 119 | 109 | private $menu_item_orphans = []; |
| 120 | 110 | private $mapped_terms_slug = []; |
| 121 | 111 | |
| 122 | 112 | private $fetch_attachments = false; |
| 123 | - private $attachment_timeout = 300; | |
| 124 | - private $attachment_retry_count = 3; | |
| 125 | 113 | private $featured_images = []; |
| 126 | 114 | |
| 127 | 115 | /** |
| 128 | 116 | * @var array[] [meta_key => meta_value] Meta value that should be set for every imported post. |
| @@ -329,10 +317,9 @@ | ||
| 329 | 317 | |
| 330 | 318 | wp_defer_term_counting( true ); |
| 331 | 319 | wp_defer_comment_counting( true ); |
| 332 | 320 | |
| 333 | - do_action( 'import_start' ); | |
| 334 | - do_action( 'templately_import_start', $this ); | |
| 321 | + do_action( 'import_start', $this ); | |
| 335 | 322 | |
| 336 | 323 | return true; |
| 337 | 324 | } |
| 338 | 325 | |
| @@ -397,9 +384,9 @@ | ||
| 397 | 384 | return; |
| 398 | 385 | } |
| 399 | 386 | |
| 400 | 387 | |
| 401 | - $processed_templates = $this->get_loop_result([], $this->import_data_key); | |
| 388 | + $processed_templates = $this->get_progress([], $this->import_data_key); | |
| 402 | 389 | if (!empty($processed_templates)) { |
| 403 | 390 | return; |
| 404 | 391 | } |
| 405 | 392 | |
| @@ -459,9 +446,9 @@ | ||
| 459 | 446 | $this->author_mapping[ $santized_old_login ] = (int) get_current_user_id(); |
| 460 | 447 | } |
| 461 | 448 | } |
| 462 | 449 | |
| 463 | - $this->set_loop_result( true, $this->import_data_key ); | |
| 450 | + $this->update_progress( true, null, $this->import_data_key ); | |
| 464 | 451 | } |
| 465 | 452 | |
| 466 | 453 | /** |
| 467 | 454 | * Create new terms based on import information |
| @@ -475,11 +462,11 @@ | ||
| 475 | 462 | 'succeed' => [], |
| 476 | 463 | 'failed' => [], |
| 477 | 464 | ]; |
| 478 | 465 | |
| 479 | - $processed_templates = $this->get_loop_result([], "wp_import_terms_" . $this->import_data_key); | |
| 466 | + $processed_templates = $this->get_progress([], "wp_import_terms_" . $this->import_data_key); | |
| 480 | 467 | if (!empty($processed_templates)) { |
| 481 | - $result = $this->get_loop_result([], "wp_import_terms_" . $this->import_data_key); | |
| 468 | + $result = $this->get_result([], "wp_import_terms_" . $this->import_data_key); | |
| 482 | 469 | return $result; |
| 483 | 470 | } |
| 484 | 471 | |
| 485 | 472 | $this->terms = apply_filters( 'wp_import_terms', $this->terms ); |
| @@ -563,9 +550,9 @@ | ||
| 563 | 550 | |
| 564 | 551 | unset( $this->terms ); |
| 565 | 552 | |
| 566 | 553 | // Add the template to the processed templates and update the session data |
| 567 | - $this->set_loop_result( $result, "wp_import_terms_" . $this->import_data_key); | |
| 554 | + $this->update_progress( true, $result, "wp_import_terms_" . $this->import_data_key); | |
| 568 | 555 | return $result; |
| 569 | 556 | } |
| 570 | 557 | |
| 571 | 558 | /** |
| @@ -645,21 +632,10 @@ | ||
| 645 | 632 | $result = !empty($result) ? $result : [ |
| 646 | 633 | 'succeed' => [], |
| 647 | 634 | 'failed' => [], |
| 648 | 635 | ]; |
| 636 | + $post = apply_filters( 'wp_import_post_data_raw', $post ); | |
| 649 | 637 | |
| 650 | - $original_post_id = $post['post_id']; | |
| 651 | - $post = apply_filters( 'wp_import_post_data_raw', $post, $this ); | |
| 652 | - | |
| 653 | - if(empty($post)){ | |
| 654 | - return $result; | |
| 655 | - } | |
| 656 | - | |
| 657 | - if(!is_array($post) && is_numeric($post)){ | |
| 658 | - $result['succeed'][ $original_post_id ] = $post; | |
| 659 | - return $result; | |
| 660 | - } | |
| 661 | - | |
| 662 | 638 | if ( ! post_type_exists( $post['post_type'] ) ) { |
| 663 | 639 | /* translators: 1: Post title, 2: Post type. */ |
| 664 | 640 | $this->output['errors'][] = sprintf( esc_html__( 'Failed to import %1$s: Invalid post type %2$s', 'elementor' ), $post['post_title'], $post['post_type'] ); |
| 665 | 641 | do_action( 'wp_import_post_exists', $post ); |
| @@ -727,12 +703,9 @@ | ||
| 727 | 703 | 'post_type' => $post['post_type'], |
| 728 | 704 | 'post_password' => $post['post_password'], |
| 729 | 705 | ]; |
| 730 | 706 | |
| 731 | - if(isset($post['original_attachment_url'])){ | |
| 732 | - $postdata['original_attachment_url'] = $post['original_attachment_url']; | |
| 733 | - } | |
| 734 | - | |
| 707 | + $original_post_id = $post['post_id']; | |
| 735 | 708 | $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post ); |
| 736 | 709 | |
| 737 | 710 | $postdata = wp_slash( $postdata ); |
| 738 | 711 | |
| @@ -1142,40 +1115,15 @@ | ||
| 1142 | 1115 | $url = rtrim( $this->base_url, '/' ) . $url; |
| 1143 | 1116 | } |
| 1144 | 1117 | |
| 1145 | 1118 | if($saved_image = $this->get_saved_image($url)){ |
| 1146 | - // $this->url_remap[ $url ] = wp_get_attachment_url( $saved_image ); | |
| 1147 | - // $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension(wp_get_attachment_url( $saved_image )); | |
| 1148 | - $upload_url = set_url_scheme( wp_get_attachment_url( $saved_image ) ); | |
| 1149 | - $this->set_url_map($url, $upload_url, true); | |
| 1119 | + $this->url_remap[ $url ] = wp_get_attachment_url( $saved_image ); | |
| 1120 | + $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension(wp_get_attachment_url( $saved_image )); | |
| 1150 | 1121 | |
| 1151 | - // AI image replacement: the imported content still carries the ORIGINAL | |
| 1152 | - // demo URL, so it must be remapped onto the replacement image here too. | |
| 1153 | - // The fresh-upload branch below does this, but when the replacement | |
| 1154 | - // image was already imported (a re-import, or the same stock photo | |
| 1155 | - // reused) we land here instead — without the map the demo URL survives | |
| 1156 | - // finalize and the pack's original images are silently kept. | |
| 1157 | - if(!empty($post['original_attachment_url'])){ | |
| 1158 | - $this->set_url_map($post['original_attachment_url'], $upload_url, true); | |
| 1159 | - | |
| 1160 | - $original_hash = sha1( $post['original_attachment_url'] ); | |
| 1161 | - | |
| 1162 | - // A stale hash from a previous import can still point the demo URL at | |
| 1163 | - // the old, unreplaced attachment — re-point it at the replacement. | |
| 1164 | - if( (int) $this->get_saved_image($post['original_attachment_url']) !== (int) $saved_image ){ | |
| 1165 | - $hash_meta_id = add_post_meta( $saved_image, '_elementor_source_image_hash', $original_hash ); | |
| 1166 | - add_post_meta( $saved_image, '_templately_image_hash_meta_id', $hash_meta_id ); | |
| 1167 | - } | |
| 1168 | - | |
| 1169 | - self::$_replace_image_ids[ $original_hash ] = (int) $saved_image; | |
| 1170 | - } | |
| 1171 | - | |
| 1172 | 1122 | $full_size_path = get_attached_file($saved_image); |
| 1173 | 1123 | $metadata = wp_get_attachment_metadata($saved_image); |
| 1174 | - $updated_metadata = $this->import_sizes($sizes, $metadata, $full_size_path, $saved_image); | |
| 1175 | - if ($updated_metadata !== false) { | |
| 1176 | - wp_update_attachment_metadata( $saved_image, $updated_metadata ); | |
| 1177 | - } | |
| 1124 | + $metadata = $this->import_sizes($sizes, $metadata, $full_size_path, $saved_image); | |
| 1125 | + wp_update_attachment_metadata( $saved_image, $metadata ); | |
| 1178 | 1126 | return $saved_image; |
| 1179 | 1127 | } |
| 1180 | 1128 | |
| 1181 | 1129 | // Check if the URL is from the wp-includes/images directory |
| @@ -1194,22 +1142,9 @@ | ||
| 1194 | 1142 | return new WP_Error( 'upload_dir_error', $upload_dir['error'] ); |
| 1195 | 1143 | } |
| 1196 | 1144 | |
| 1197 | 1145 | // Move the file to the uploads dir. |
| 1198 | - // | |
| 1199 | - // The attachment url is attacker-reachable — a cloud template can point an | |
| 1200 | - // image anywhere — so the url-derived name is sanitized, and an extension | |
| 1201 | - // WordPress does not recognise as an uploadable type is dropped rather than | |
| 1202 | - // carried into the destination path. fetch_remote_file() re-derives the | |
| 1203 | - // extension from the response and validates it before writing, so dropping | |
| 1204 | - // an unusable one here costs nothing. | |
| 1205 | - $file_name = sanitize_file_name( basename( parse_url( $url, PHP_URL_PATH ) ) ); | |
| 1206 | - if ( pathinfo( $file_name, PATHINFO_EXTENSION ) ) { | |
| 1207 | - $url_filetype = wp_check_filetype( $file_name ); | |
| 1208 | - if ( empty( $url_filetype['type'] ) ) { | |
| 1209 | - $file_name = pathinfo( $file_name, PATHINFO_FILENAME ); | |
| 1210 | - } | |
| 1211 | - } | |
| 1146 | + $file_name = basename( parse_url( $url, PHP_URL_PATH ) ); | |
| 1212 | 1147 | $file_name = wp_unique_filename( $upload_dir['path'], $file_name ); |
| 1213 | 1148 | $dest_file = $upload_dir['path'] . "/$file_name"; |
| 1214 | 1149 | $start = microtime(true); |
| 1215 | 1150 | |
| @@ -1217,13 +1152,8 @@ | ||
| 1217 | 1152 | if ( null === $upload ) { |
| 1218 | 1153 | $upload = $this->fetch_remote_file( $url, $dest_file, $upload_dir ); |
| 1219 | 1154 | } |
| 1220 | 1155 | |
| 1221 | - // Normalize URL scheme to match the current site scheme (fixes HTTP URLs on HTTPS multisites). | |
| 1222 | - if ( ! is_wp_error( $upload ) && ! empty( $upload['url'] ) ) { | |
| 1223 | - $upload['url'] = set_url_scheme( $upload['url'] ); | |
| 1224 | - } | |
| 1225 | - | |
| 1226 | 1156 | $end = microtime(true); |
| 1227 | 1157 | $duration = $end - $start; |
| 1228 | 1158 | error_log('Duration: ' . $duration); |
| 1229 | 1159 | |
| @@ -1237,10 +1167,9 @@ | ||
| 1237 | 1167 | } else { |
| 1238 | 1168 | return new WP_Error( 'attachment_processing_error', esc_html__( 'Invalid file type', 'elementor' ) ); |
| 1239 | 1169 | } |
| 1240 | 1170 | |
| 1241 | - // $this->url_remap[ $post['guid'] ] = $upload['url']; // r13735, really needed? | |
| 1242 | - // $this->set_url_map($post['guid'], $upload['url']); | |
| 1171 | + $this->url_remap[ $post['guid'] ] = $upload['url']; // r13735, really needed? | |
| 1243 | 1172 | $post['guid'] = $upload['url']; |
| 1244 | 1173 | |
| 1245 | 1174 | // As per wp-admin/includes/upload.php. |
| 1246 | 1175 | $post_id = wp_insert_attachment( $post, $upload['file'] ); |
| @@ -1256,46 +1185,21 @@ | ||
| 1256 | 1185 | |
| 1257 | 1186 | // error_log('Metadata: ' . print_r($metadata, true)); |
| 1258 | 1187 | |
| 1259 | 1188 | // For gutenberg pages |
| 1260 | - $updated_metadata = $this->import_sizes($sizes, $metadata, $upload['file'], $post_id); | |
| 1189 | + $metadata = $this->import_sizes($sizes, $metadata, $upload['file'], $post_id); | |
| 1261 | 1190 | |
| 1262 | 1191 | // error_log('Metadata: ' . print_r($metadata, true)); |
| 1263 | - if ($updated_metadata !== false) { | |
| 1264 | - wp_update_attachment_metadata( $post_id, $updated_metadata ); | |
| 1265 | - } else { | |
| 1266 | - wp_update_attachment_metadata( $post_id, $metadata ); | |
| 1267 | - } | |
| 1192 | + wp_update_attachment_metadata( $post_id, $metadata ); | |
| 1268 | 1193 | |
| 1269 | 1194 | // @todo: add missing image sizes |
| 1270 | - if(defined('TEMPLATELY_DEV') && TEMPLATELY_DEV){ | |
| 1271 | - update_post_meta( $post_id, '_templately_original_id', $original_post_id ); | |
| 1272 | - update_post_meta( $post_id, '_templately_original_url', $url ); | |
| 1273 | 1195 | |
| 1274 | - if(!empty($post['original_attachment_url'])){ | |
| 1275 | - update_post_meta( $post_id, '_templately_demo_url', $post['original_attachment_url'] ); | |
| 1276 | - } | |
| 1277 | - } | |
| 1278 | - | |
| 1279 | 1196 | update_post_meta( $post_id, '_elementor_source_image_hash', sha1( $url ) ); |
| 1280 | 1197 | self::$_replace_image_ids[ sha1( $url ) ] = $post_id; |
| 1281 | 1198 | |
| 1282 | - // add a second hash for original demo url | |
| 1283 | - // if user is replacing image. | |
| 1284 | - // so we can also match original demo url to new image | |
| 1285 | - if(!empty($post['original_attachment_url'])){ | |
| 1286 | - $hash_meta_id = add_post_meta( $post_id, '_elementor_source_image_hash', sha1( $post['original_attachment_url'] ) ); | |
| 1287 | - add_post_meta( $post_id, '_templately_image_hash_meta_id', $hash_meta_id ); | |
| 1288 | - self::$_replace_image_ids[ sha1( $post['original_attachment_url'] ) ] = $post_id; | |
| 1289 | - } | |
| 1290 | - | |
| 1291 | 1199 | // Remap resized image URLs, works by stripping the extension and remapping the URL stub. |
| 1292 | 1200 | if ( preg_match( '!^image/!', $info['type'] ) ) { |
| 1293 | - // $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension($upload['url']); | |
| 1294 | - $this->set_url_map($url, $upload['url'], true); | |
| 1295 | - if(!empty($post['original_attachment_url'])){ | |
| 1296 | - $this->set_url_map($post['original_attachment_url'], $upload['url'], true); | |
| 1297 | - } | |
| 1201 | + $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension($upload['url']); | |
| 1298 | 1202 | } |
| 1299 | 1203 | |
| 1300 | 1204 | return $post_id; |
| 1301 | 1205 | } |
| @@ -1301,29 +1205,13 @@ | ||
| 1301 | 1205 | } |
| 1302 | 1206 | |
| 1303 | 1207 | private function remove_extension($url) { |
| 1304 | 1208 | $parts = pathinfo($url); |
| 1305 | - // pathinfo() omits 'extension' for a dotless name, and 'dirname' for an | |
| 1306 | - // empty one. Remote attachment urls are not obliged to carry an extension | |
| 1307 | - // (`.../media/1234`), and the url of an attachment that has since been | |
| 1308 | - // deleted resolves to ''. | |
| 1309 | - $dirname = isset( $parts['dirname'] ) ? $parts['dirname'] : ''; | |
| 1310 | - $basename = isset( $parts['basename'] ) ? $parts['basename'] : ''; | |
| 1311 | - $extension = isset( $parts['extension'] ) ? $parts['extension'] : ''; | |
| 1312 | - $name = '' === $extension ? $basename : basename($basename, ".{$extension}"); // PATHINFO_FILENAME in PHP 5.2 | |
| 1209 | + $name = basename($parts['basename'], ".{$parts['extension']}"); // PATHINFO_FILENAME in PHP 5.2 | |
| 1313 | 1210 | |
| 1314 | - return $dirname . '/' . $name; | |
| 1211 | + return $parts['dirname'] . '/' . $name; | |
| 1315 | 1212 | } |
| 1316 | 1213 | |
| 1317 | - public function set_url_map($original_url, $new_url, $remove_extension = false){ | |
| 1318 | - $this->url_remap[ $original_url ] = $new_url; | |
| 1319 | - if($remove_extension){ | |
| 1320 | - $original_url = $this->remove_extension($original_url); | |
| 1321 | - $new_url = $this->remove_extension($new_url); | |
| 1322 | - $this->url_remap[ $original_url ] = $new_url; | |
| 1323 | - } | |
| 1324 | - } | |
| 1325 | - | |
| 1326 | 1214 | /** |
| 1327 | 1215 | * Attempt to download a remote file attachment |
| 1328 | 1216 | * |
| 1329 | 1217 | * @param string $url URL of item to fetch |
| @@ -1346,13 +1234,13 @@ | ||
| 1346 | 1234 | } |
| 1347 | 1235 | |
| 1348 | 1236 | // Fetch the remote URL and write it to the placeholder file. |
| 1349 | 1237 | $attempt = 0; |
| 1350 | - $retry_count = $this->attachment_retry_count; | |
| 1238 | + $retry_count = 3; | |
| 1351 | 1239 | $remote_response = null; |
| 1352 | 1240 | do { |
| 1353 | 1241 | $remote_response = wp_safe_remote_get( $url, [ |
| 1354 | - 'timeout' => $this->attachment_timeout, | |
| 1242 | + 'timeout' => 300, | |
| 1355 | 1243 | 'stream' => true, |
| 1356 | 1244 | 'filename' => $tmp_file_name, |
| 1357 | 1245 | 'headers' => [ |
| 1358 | 1246 | 'Accept-Encoding' => 'identity', |
| @@ -1407,18 +1295,12 @@ | ||
| 1407 | 1295 | |
| 1408 | 1296 | return new WP_Error( 'import_file_error', sprintf( esc_html__( 'Remote file is too large, limit is %s', 'elementor' ), size_format( $max_size ) ) ); |
| 1409 | 1297 | } |
| 1410 | 1298 | |
| 1411 | - // Override file name with Content-Disposition header value. The header is | |
| 1412 | - // whatever the remote chose to send, so it is sanitized before it is allowed | |
| 1413 | - // anywhere near a path: sanitize_file_name() strips directory separators and | |
| 1414 | - // neutralizes the inner extension of a double-extension name. | |
| 1299 | + // Override file name with Content-Disposition header value. | |
| 1415 | 1300 | if ( ! empty( $headers['content-disposition'] ) ) { |
| 1416 | 1301 | $file_name_from_disposition = self::get_filename_from_disposition( (array) $headers['content-disposition'] ); |
| 1417 | 1302 | if ( $file_name_from_disposition ) { |
| 1418 | - $file_name_from_disposition = sanitize_file_name( $file_name_from_disposition ); | |
| 1419 | - } | |
| 1420 | - if ( $file_name_from_disposition ) { | |
| 1421 | 1303 | $file_name = $file_name_from_disposition; |
| 1422 | 1304 | } |
| 1423 | 1305 | } |
| 1424 | 1306 | |
| @@ -1442,29 +1324,11 @@ | ||
| 1442 | 1324 | $file_name = $proper_filename; |
| 1443 | 1325 | } |
| 1444 | 1326 | |
| 1445 | 1327 | if ( ( ! $type || ! $ext ) && ! current_user_can( 'unfiltered_upload' ) ) { |
| 1446 | - @unlink( $tmp_file_name ); | |
| 1447 | - | |
| 1448 | 1328 | return new WP_Error( 'import_file_error', esc_html__( 'Sorry, this file type is not permitted for security reasons.', 'elementor' ) ); |
| 1449 | 1329 | } |
| 1450 | 1330 | |
| 1451 | - // The type check above ran against $file_name (Content-Disposition), but the | |
| 1452 | - // write lands on $new_file, whose name came from the request url path. When | |
| 1453 | - // those two extensions disagree the check guarantees nothing about what is | |
| 1454 | - // actually written — an image/gif verdict on `ok.gif` would let the bytes go | |
| 1455 | - // to a `.php` destination. Re-derive the destination from the validated name | |
| 1456 | - // so the two can never diverge. (CVE-2026-18438) | |
| 1457 | - if ( $ext && strtolower( pathinfo( $new_file, PATHINFO_EXTENSION ) ) !== strtolower( $ext ) ) { | |
| 1458 | - $file_name = wp_unique_filename( $uploads['path'], $file_name ); | |
| 1459 | - $new_file = $uploads['path'] . "/$file_name"; | |
| 1460 | - } | |
| 1461 | - | |
| 1462 | - // Whatever the branch above decided, the reported name must describe the file | |
| 1463 | - // that is actually on disk — the remapped url in the imported content is built | |
| 1464 | - // from it. | |
| 1465 | - $file_name = wp_basename( $new_file ); | |
| 1466 | - | |
| 1467 | 1331 | $move_new_file = copy( $tmp_file_name, $new_file ); |
| 1468 | 1332 | |
| 1469 | 1333 | if ( ! $move_new_file ) { |
| 1470 | 1334 | @unlink( $tmp_file_name ); |
| @@ -1484,12 +1348,12 @@ | ||
| 1484 | 1348 | 'error' => false, |
| 1485 | 1349 | ]; |
| 1486 | 1350 | |
| 1487 | 1351 | // Keep track of the old and new urls so we can substitute them later. |
| 1488 | - $this->set_url_map($url, $upload['url']); | |
| 1352 | + $this->url_remap[ $url ] = $upload['url']; | |
| 1489 | 1353 | // Keep track of the destination if the remote url is redirected somewhere else. |
| 1490 | 1354 | if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] !== $url ) { |
| 1491 | - $this->set_url_map($headers['x-final-location'], $upload['url']); | |
| 1355 | + $this->url_remap[ $headers['x-final-location'] ] = $upload['url']; | |
| 1492 | 1356 | } |
| 1493 | 1357 | |
| 1494 | 1358 | return $upload; |
| 1495 | 1359 | } |
| @@ -1503,9 +1367,9 @@ | ||
| 1503 | 1367 | * @access private |
| 1504 | 1368 | * |
| 1505 | 1369 | * @param string $url The image URL. |
| 1506 | 1370 | * |
| 1507 | - * @return false|int New image ID or false. | |
| 1371 | + * @return false|array New image ID or false. | |
| 1508 | 1372 | */ |
| 1509 | 1373 | private function get_saved_image( $url ) { |
| 1510 | 1374 | global $wpdb; |
| 1511 | 1375 | |
| @@ -1514,26 +1378,13 @@ | ||
| 1514 | 1378 | if ( isset( self::$_replace_image_ids[ $hash ] ) ) { |
| 1515 | 1379 | return self::$_replace_image_ids[ $hash ]; |
| 1516 | 1380 | } |
| 1517 | 1381 | |
| 1518 | - // Newest row wins. A URL can be claimed by more than one attachment: an | |
| 1519 | - // AI/customizer image replacement registers the ORIGINAL demo URL against | |
| 1520 | - // the REPLACEMENT attachment (see process_attachment), while a previous | |
| 1521 | - // plain import of the same pack already claimed that URL for the original | |
| 1522 | - // image — and that older row is never cleaned up (clear_old_el_cache only | |
| 1523 | - // tracks replacement hashes). Without the ordering the stale original wins | |
| 1524 | - // and the replacement is silently ignored on every re-import. | |
| 1525 | - // | |
| 1526 | - // The static cache above short-circuits this, but the import is split | |
| 1527 | - // across many requests (each SSE `continue` is a fresh PHP process), so | |
| 1528 | - // the DB is the real source of truth for anything set in an earlier step. | |
| 1529 | 1382 | $post_id = $wpdb->get_var( |
| 1530 | 1383 | $wpdb->prepare( |
| 1531 | 1384 | 'SELECT `post_id` FROM `' . $wpdb->postmeta . '` |
| 1532 | 1385 | WHERE `meta_key` = \'_elementor_source_image_hash\' |
| 1533 | 1386 | AND `meta_value` = %s |
| 1534 | - ORDER BY `meta_id` DESC | |
| 1535 | - LIMIT 1 | |
| 1536 | 1387 | ;', |
| 1537 | 1388 | $hash |
| 1538 | 1389 | ) |
| 1539 | 1390 | ); |
| @@ -1547,10 +1398,8 @@ | ||
| 1547 | 1398 | } |
| 1548 | 1399 | |
| 1549 | 1400 | |
| 1550 | 1401 | public function import_sizes($sizes, $metadata, $full_size_file, $post_id) { |
| 1551 | - $metadata_modified = false; | |
| 1552 | - | |
| 1553 | 1402 | if (!empty($sizes)) { |
| 1554 | 1403 | do_action('templately_import.finalize_gutenberg_attachment', $post_id); |
| 1555 | 1404 | |
| 1556 | 1405 | foreach ($sizes as $size_name => $size) { |
| @@ -1563,9 +1412,8 @@ | ||
| 1563 | 1412 | $missing_size = $this->generate_missing_size_from_full($full_size_file, $unique_destination_file, $size); |
| 1564 | 1413 | if ($missing_size && !is_wp_error($missing_size)) { |
| 1565 | 1414 | unset($missing_size['path']); |
| 1566 | 1415 | $metadata['sizes'][$size_name] = $missing_size; |
| 1567 | - $metadata_modified = true; | |
| 1568 | 1416 | do_action('templately_import.finalize_gutenberg_attachment', $post_id, $size_dimension); |
| 1569 | 1417 | } |
| 1570 | 1418 | } |
| 1571 | 1419 | } |
| @@ -1570,11 +1418,9 @@ | ||
| 1570 | 1418 | } |
| 1571 | 1419 | } |
| 1572 | 1420 | } |
| 1573 | 1421 | } |
| 1574 | - | |
| 1575 | - // Only return metadata if new sizes were actually added | |
| 1576 | - return $metadata_modified ? $metadata : false; | |
| 1422 | + return $metadata; | |
| 1577 | 1423 | } |
| 1578 | 1424 | |
| 1579 | 1425 | public function generate_missing_size_from_full($full_size_file, $destination_file, $size) { |
| 1580 | 1426 | // Generate the missing size from the full-size image |
| @@ -1597,9 +1443,9 @@ | ||
| 1597 | 1443 | } |
| 1598 | 1444 | |
| 1599 | 1445 | public function size_exists_in_metadata($size_file, $metadata) { |
| 1600 | 1446 | if (isset($metadata['sizes']) && is_array($metadata['sizes'])) { |
| 1601 | - foreach ($metadata['sizes'] as $size_info) { | |
| 1447 | + foreach ($metadata['sizes'] as $size => $size_info) { | |
| 1602 | 1448 | if ($size_info['file'] == $size_file) { |
| 1603 | 1449 | return true; |
| 1604 | 1450 | } |
| 1605 | 1451 | } |
| @@ -1803,9 +1649,9 @@ | ||
| 1803 | 1649 | * @param $post_id |
| 1804 | 1650 | * |
| 1805 | 1651 | * @return void |
| 1806 | 1652 | */ |
| 1807 | - public function update_post_meta( $post_id ) { | |
| 1653 | + private function update_post_meta( $post_id ) { | |
| 1808 | 1654 | foreach ( $this->posts_meta as $meta_key => $meta_value ) { |
| 1809 | 1655 | update_post_meta( $post_id, $meta_key, $meta_value ); |
| 1810 | 1656 | } |
| 1811 | 1657 | } |
| @@ -1816,43 +1662,14 @@ | ||
| 1816 | 1662 | return $this->output; |
| 1817 | 1663 | } |
| 1818 | 1664 | |
| 1819 | 1665 | /** |
| 1820 | - * Register Templately with Jetpack Sync's known importers. | |
| 1821 | - * | |
| 1822 | - * This filter callback adds Templately to Jetpack's list of known importers, | |
| 1823 | - * ensuring that 'templately' is sent to WordPress.com instead of the full class name. | |
| 1824 | - * This provides cleaner analytics data and better tracking. | |
| 1825 | - * | |
| 1826 | - * @param array $known_importers Array of known importers with class names as keys and friendly names as values. | |
| 1827 | - * @return array Modified array of known importers. | |
| 1828 | - */ | |
| 1829 | - public function register_jetpack_importer( $known_importers ) { | |
| 1830 | - $known_importers[ __CLASS__ ] = 'templately'; | |
| 1831 | - return $known_importers; | |
| 1832 | - } | |
| 1833 | - | |
| 1834 | - /** | |
| 1835 | - * There is deliberately NO `parent::__construct()` call here. | |
| 1836 | - * | |
| 1837 | - * `WP_Importer` declared an EMPTY constructor up to WordPress 7.0 and | |
| 1838 | - * removed it in 7.1. Calling a parent constructor the parent does not | |
| 1839 | - * declare throws `Error: Cannot call constructor`, so the call fataled every | |
| 1840 | - * Full Site Import on 7.1 — and it had never done anything on the versions | |
| 1841 | - * where it resolved, because the body was empty. | |
| 1842 | - * | |
| 1843 | - * Nothing contained it: `Error` is not an `Exception` in PHP 7+ (siblings | |
| 1844 | - * under `Throwable`), and the outer import handlers catch `Exception`. The | |
| 1845 | - * import streams over SSE, so the fatal landed mid-stream with no `error` | |
| 1846 | - * event: the connection just stopped. | |
| 1847 | - * | |
| 1848 | - * Do not "restore" it for symmetry. `tests/unit/Core/Importer/test-WPImportConstruction.php` | |
| 1849 | - * pins this, and only discriminates on a WP 7.1+ host. | |
| 1850 | - * | |
| 1851 | 1666 | * @param $file |
| 1852 | 1667 | * @param array $args |
| 1853 | 1668 | */ |
| 1854 | 1669 | public function __construct( $file, array $args = [] ) { |
| 1670 | + parent::__construct(); | |
| 1671 | + | |
| 1855 | 1672 | $this->args = $args; |
| 1856 | 1673 | $this->session_id = $args['session_id']; |
| 1857 | 1674 | |
| 1858 | 1675 | if ( ! empty( $args['json'] ) ) { |
| @@ -1871,16 +1688,8 @@ | ||
| 1871 | 1688 | if ( ! empty( $this->args['fetch_attachments'] ) ) { |
| 1872 | 1689 | $this->fetch_attachments = true; |
| 1873 | 1690 | } |
| 1874 | 1691 | |
| 1875 | - if ( isset( $this->args['attachment_timeout'] ) && is_numeric( $this->args['attachment_timeout'] ) ) { | |
| 1876 | - $this->attachment_timeout = max( 1, (int) $this->args['attachment_timeout'] ); | |
| 1877 | - } | |
| 1878 | - | |
| 1879 | - if ( isset( $this->args['attachment_retries'] ) && is_numeric( $this->args['attachment_retries'] ) ) { | |
| 1880 | - $this->attachment_retry_count = max( 1, (int) $this->args['attachment_retries'] + 1 ); | |
| 1881 | - } | |
| 1882 | - | |
| 1883 | 1692 | if ( isset( $this->args['posts'] ) && is_array( $this->args['posts'] ) ) { |
| 1884 | 1693 | $this->processed_posts = $this->args['posts']; |
| 1885 | 1694 | } |
| 1886 | 1695 | |
| @@ -1898,9 +1707,6 @@ | ||
| 1898 | 1707 | |
| 1899 | 1708 | if ( ! empty( $this->args['terms_meta'] ) ) { |
| 1900 | 1709 | $this->terms_meta = $this->args['terms_meta']; |
| 1901 | 1710 | } |
| 1902 | - | |
| 1903 | - // Register with Jetpack Sync for better analytics tracking. | |
| 1904 | - add_filter( 'jetpack_sync_known_importers', [ $this, 'register_jetpack_importer' ] ); | |
| 1905 | 1711 | } |
| 1906 | 1712 | } |