PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.3.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.3.2
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/WPImport.php +22 -119 3.6.1 → 3.3.2 View file →
@@ -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 = [];
@@ -327,10 +317,9 @@
327 317
328 318 wp_defer_term_counting( true );
329 319 wp_defer_comment_counting( true );
330 320
331 - do_action( 'import_start' );
332 - do_action( 'templately_import_start', $this );
321 + do_action( 'import_start', $this );
333 322
334 323 return true;
335 324 }
336 325
@@ -395,9 +384,9 @@
395 384 return;
396 385 }
397 386
398 387
399 - $processed_templates = $this->get_loop_result([], $this->import_data_key);
388 + $processed_templates = $this->get_progress([], $this->import_data_key);
400 389 if (!empty($processed_templates)) {
401 390 return;
402 391 }
403 392
@@ -457,9 +446,9 @@
457 446 $this->author_mapping[ $santized_old_login ] = (int) get_current_user_id();
458 447 }
459 448 }
460 449
461 - $this->set_loop_result( true, $this->import_data_key );
450 + $this->update_progress( true, null, $this->import_data_key );
462 451 }
463 452
464 453 /**
465 454 * Create new terms based on import information
@@ -473,11 +462,11 @@
473 462 'succeed' => [],
474 463 'failed' => [],
475 464 ];
476 465
477 - $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);
478 467 if (!empty($processed_templates)) {
479 - $result = $this->get_loop_result([], "wp_import_terms_" . $this->import_data_key);
468 + $result = $this->get_result([], "wp_import_terms_" . $this->import_data_key);
480 469 return $result;
481 470 }
482 471
483 472 $this->terms = apply_filters( 'wp_import_terms', $this->terms );
@@ -561,9 +550,9 @@
561 550
562 551 unset( $this->terms );
563 552
564 553 // Add the template to the processed templates and update the session data
565 - $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);
566 555 return $result;
567 556 }
568 557
569 558 /**
@@ -643,21 +632,10 @@
643 632 $result = !empty($result) ? $result : [
644 633 'succeed' => [],
645 634 'failed' => [],
646 635 ];
636 + $post = apply_filters( 'wp_import_post_data_raw', $post );
647 637
648 - $original_post_id = $post['post_id'];
649 - $post = apply_filters( 'wp_import_post_data_raw', $post, $this );
650 -
651 - if(empty($post)){
652 - return $result;
653 - }
654 -
655 - if(!is_array($post) && is_numeric($post)){
656 - $result['succeed'][ $original_post_id ] = $post;
657 - return $result;
658 - }
659 -
660 638 if ( ! post_type_exists( $post['post_type'] ) ) {
661 639 /* translators: 1: Post title, 2: Post type. */
662 640 $this->output['errors'][] = sprintf( esc_html__( 'Failed to import %1$s: Invalid post type %2$s', 'elementor' ), $post['post_title'], $post['post_type'] );
663 641 do_action( 'wp_import_post_exists', $post );
@@ -725,12 +703,9 @@
725 703 'post_type' => $post['post_type'],
726 704 'post_password' => $post['post_password'],
727 705 ];
728 706
729 - if(isset($post['original_attachment_url'])){
730 - $postdata['original_attachment_url'] = $post['original_attachment_url'];
731 - }
732 -
707 + $original_post_id = $post['post_id'];
733 708 $postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $post );
734 709
735 710 $postdata = wp_slash( $postdata );
736 711
@@ -1140,24 +1115,15 @@
1140 1115 $url = rtrim( $this->base_url, '/' ) . $url;
1141 1116 }
1142 1117
1143 1118 if($saved_image = $this->get_saved_image($url)){
1144 - // $this->url_remap[ $url ] = wp_get_attachment_url( $saved_image );
1145 - // $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension(wp_get_attachment_url( $saved_image ));
1146 - $upload_url = set_url_scheme( wp_get_attachment_url( $saved_image ) );
1147 - $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 ));
1148 1121
1149 - if(!empty($post['original_attachment_url']) && !$this->get_saved_image($post['original_attachment_url'])){
1150 - add_post_meta( $saved_image, '_elementor_source_image_hash', sha1( $post['original_attachment_url'] ) );
1151 - self::$_replace_image_ids[ sha1( $post['original_attachment_url'] ) ] = $post_id;
1152 - }
1153 -
1154 1122 $full_size_path = get_attached_file($saved_image);
1155 1123 $metadata = wp_get_attachment_metadata($saved_image);
1156 - $updated_metadata = $this->import_sizes($sizes, $metadata, $full_size_path, $saved_image);
1157 - if ($updated_metadata !== false) {
1158 - wp_update_attachment_metadata( $saved_image, $updated_metadata );
1159 - }
1124 + $metadata = $this->import_sizes($sizes, $metadata, $full_size_path, $saved_image);
1125 + wp_update_attachment_metadata( $saved_image, $metadata );
1160 1126 return $saved_image;
1161 1127 }
1162 1128
1163 1129 // Check if the URL is from the wp-includes/images directory
@@ -1186,13 +1152,8 @@
1186 1152 if ( null === $upload ) {
1187 1153 $upload = $this->fetch_remote_file( $url, $dest_file, $upload_dir );
1188 1154 }
1189 1155
1190 - // Normalize URL scheme to match the current site scheme (fixes HTTP URLs on HTTPS multisites).
1191 - if ( ! is_wp_error( $upload ) && ! empty( $upload['url'] ) ) {
1192 - $upload['url'] = set_url_scheme( $upload['url'] );
1193 - }
1194 -
1195 1156 $end = microtime(true);
1196 1157 $duration = $end - $start;
1197 1158 error_log('Duration: ' . $duration);
1198 1159
@@ -1206,10 +1167,9 @@
1206 1167 } else {
1207 1168 return new WP_Error( 'attachment_processing_error', esc_html__( 'Invalid file type', 'elementor' ) );
1208 1169 }
1209 1170
1210 - // $this->url_remap[ $post['guid'] ] = $upload['url']; // r13735, really needed?
1211 - // $this->set_url_map($post['guid'], $upload['url']);
1171 + $this->url_remap[ $post['guid'] ] = $upload['url']; // r13735, really needed?
1212 1172 $post['guid'] = $upload['url'];
1213 1173
1214 1174 // As per wp-admin/includes/upload.php.
1215 1175 $post_id = wp_insert_attachment( $post, $upload['file'] );
@@ -1225,46 +1185,21 @@
1225 1185
1226 1186 // error_log('Metadata: ' . print_r($metadata, true));
1227 1187
1228 1188 // For gutenberg pages
1229 - $updated_metadata = $this->import_sizes($sizes, $metadata, $upload['file'], $post_id);
1189 + $metadata = $this->import_sizes($sizes, $metadata, $upload['file'], $post_id);
1230 1190
1231 1191 // error_log('Metadata: ' . print_r($metadata, true));
1232 - if ($updated_metadata !== false) {
1233 - wp_update_attachment_metadata( $post_id, $updated_metadata );
1234 - } else {
1235 - wp_update_attachment_metadata( $post_id, $metadata );
1236 - }
1192 + wp_update_attachment_metadata( $post_id, $metadata );
1237 1193
1238 1194 // @todo: add missing image sizes
1239 - if(defined('TEMPLATELY_DEV') && TEMPLATELY_DEV){
1240 - update_post_meta( $post_id, '_templately_original_id', $original_post_id );
1241 - update_post_meta( $post_id, '_templately_original_url', $url );
1242 1195
1243 - if(!empty($post['original_attachment_url'])){
1244 - update_post_meta( $post_id, '_templately_demo_url', $post['original_attachment_url'] );
1245 - }
1246 - }
1247 -
1248 1196 update_post_meta( $post_id, '_elementor_source_image_hash', sha1( $url ) );
1249 1197 self::$_replace_image_ids[ sha1( $url ) ] = $post_id;
1250 1198
1251 - // add a second hash for original demo url
1252 - // if user is replacing image.
1253 - // so we can also match original demo url to new image
1254 - if(!empty($post['original_attachment_url'])){
1255 - $hash_meta_id = add_post_meta( $post_id, '_elementor_source_image_hash', sha1( $post['original_attachment_url'] ) );
1256 - add_post_meta( $post_id, '_templately_image_hash_meta_id', $hash_meta_id );
1257 - self::$_replace_image_ids[ sha1( $post['original_attachment_url'] ) ] = $post_id;
1258 - }
1259 -
1260 1199 // Remap resized image URLs, works by stripping the extension and remapping the URL stub.
1261 1200 if ( preg_match( '!^image/!', $info['type'] ) ) {
1262 - // $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension($upload['url']);
1263 - $this->set_url_map($url, $upload['url'], true);
1264 - if(!empty($post['original_attachment_url'])){
1265 - $this->set_url_map($post['original_attachment_url'], $upload['url'], true);
1266 - }
1201 + $this->url_remap[ $this->remove_extension($url) ] = $this->remove_extension($upload['url']);
1267 1202 }
1268 1203
1269 1204 return $post_id;
1270 1205 }
@@ -1275,17 +1210,8 @@
1275 1210
1276 1211 return $parts['dirname'] . '/' . $name;
1277 1212 }
1278 1213
1279 - public function set_url_map($original_url, $new_url, $remove_extension = false){
1280 - $this->url_remap[ $original_url ] = $new_url;
1281 - if($remove_extension){
1282 - $original_url = $this->remove_extension($original_url);
1283 - $new_url = $this->remove_extension($new_url);
1284 - $this->url_remap[ $original_url ] = $new_url;
1285 - }
1286 - }
1287 -
1288 1214 /**
1289 1215 * Attempt to download a remote file attachment
1290 1216 *
1291 1217 * @param string $url URL of item to fetch
@@ -1422,12 +1348,12 @@
1422 1348 'error' => false,
1423 1349 ];
1424 1350
1425 1351 // Keep track of the old and new urls so we can substitute them later.
1426 - $this->set_url_map($url, $upload['url']);
1352 + $this->url_remap[ $url ] = $upload['url'];
1427 1353 // Keep track of the destination if the remote url is redirected somewhere else.
1428 1354 if ( isset( $headers['x-final-location'] ) && $headers['x-final-location'] !== $url ) {
1429 - $this->set_url_map($headers['x-final-location'], $upload['url']);
1355 + $this->url_remap[ $headers['x-final-location'] ] = $upload['url'];
1430 1356 }
1431 1357
1432 1358 return $upload;
1433 1359 }
@@ -1441,9 +1367,9 @@
1441 1367 * @access private
1442 1368 *
1443 1369 * @param string $url The image URL.
1444 1370 *
1445 - * @return false|int New image ID or false.
1371 + * @return false|array New image ID or false.
1446 1372 */
1447 1373 private function get_saved_image( $url ) {
1448 1374 global $wpdb;
1449 1375
@@ -1472,10 +1398,8 @@
1472 1398 }
1473 1399
1474 1400
1475 1401 public function import_sizes($sizes, $metadata, $full_size_file, $post_id) {
1476 - $metadata_modified = false;
1477 -
1478 1402 if (!empty($sizes)) {
1479 1403 do_action('templately_import.finalize_gutenberg_attachment', $post_id);
1480 1404
1481 1405 foreach ($sizes as $size_name => $size) {
@@ -1488,9 +1412,8 @@
1488 1412 $missing_size = $this->generate_missing_size_from_full($full_size_file, $unique_destination_file, $size);
1489 1413 if ($missing_size && !is_wp_error($missing_size)) {
1490 1414 unset($missing_size['path']);
1491 1415 $metadata['sizes'][$size_name] = $missing_size;
1492 - $metadata_modified = true;
1493 1416 do_action('templately_import.finalize_gutenberg_attachment', $post_id, $size_dimension);
1494 1417 }
1495 1418 }
1496 1419 }
@@ -1495,11 +1418,9 @@
1495 1418 }
1496 1419 }
1497 1420 }
1498 1421 }
1499 -
1500 - // Only return metadata if new sizes were actually added
1501 - return $metadata_modified ? $metadata : false;
1422 + return $metadata;
1502 1423 }
1503 1424
1504 1425 public function generate_missing_size_from_full($full_size_file, $destination_file, $size) {
1505 1426 // Generate the missing size from the full-size image
@@ -1522,9 +1443,9 @@
1522 1443 }
1523 1444
1524 1445 public function size_exists_in_metadata($size_file, $metadata) {
1525 1446 if (isset($metadata['sizes']) && is_array($metadata['sizes'])) {
1526 - foreach ($metadata['sizes'] as $size_info) {
1447 + foreach ($metadata['sizes'] as $size => $size_info) {
1527 1448 if ($size_info['file'] == $size_file) {
1528 1449 return true;
1529 1450 }
1530 1451 }
@@ -1728,9 +1649,9 @@
1728 1649 * @param $post_id
1729 1650 *
1730 1651 * @return void
1731 1652 */
1732 - public function update_post_meta( $post_id ) {
1653 + private function update_post_meta( $post_id ) {
1733 1654 foreach ( $this->posts_meta as $meta_key => $meta_value ) {
1734 1655 update_post_meta( $post_id, $meta_key, $meta_value );
1735 1656 }
1736 1657 }
@@ -1741,23 +1662,8 @@
1741 1662 return $this->output;
1742 1663 }
1743 1664
1744 1665 /**
1745 - * Register Templately with Jetpack Sync's known importers.
1746 - *
1747 - * This filter callback adds Templately to Jetpack's list of known importers,
1748 - * ensuring that 'templately' is sent to WordPress.com instead of the full class name.
1749 - * This provides cleaner analytics data and better tracking.
1750 - *
1751 - * @param array $known_importers Array of known importers with class names as keys and friendly names as values.
1752 - * @return array Modified array of known importers.
1753 - */
1754 - public function register_jetpack_importer( $known_importers ) {
1755 - $known_importers[ __CLASS__ ] = 'templately';
1756 - return $known_importers;
1757 - }
1758 -
1759 - /**
1760 1666 * @param $file
1761 1667 * @param array $args
1762 1668 */
1763 1669 public function __construct( $file, array $args = [] ) {
@@ -1801,9 +1707,6 @@
1801 1707
1802 1708 if ( ! empty( $this->args['terms_meta'] ) ) {
1803 1709 $this->terms_meta = $this->args['terms_meta'];
1804 1710 }
1805 -
1806 - // Register with Jetpack Sync for better analytics tracking.
1807 - add_filter( 'jetpack_sync_known_importers', [ $this, 'register_jetpack_importer' ] );
1808 1711 }
1809 1712 }