Changeset 3790778
- Timestamp:
- 11/08/2026 09:45:04 AM (39 hours ago)
- Location:
- siculotech-url-domain-migrator
- Files:
-
- 12 added
- 6 edited
-
tags/1.9.1 (added)
-
tags/1.9.1/assets (added)
-
tags/1.9.1/assets/js (added)
-
tags/1.9.1/assets/js/migrator.js (added)
-
tags/1.9.1/languages (added)
-
tags/1.9.1/languages/siculotech-url-domain-migrator-es_ES.mo (added)
-
tags/1.9.1/languages/siculotech-url-domain-migrator-es_ES.po (added)
-
tags/1.9.1/languages/siculotech-url-domain-migrator-it_IT.mo (added)
-
tags/1.9.1/languages/siculotech-url-domain-migrator-it_IT.po (added)
-
tags/1.9.1/languages/siculotech-url-migrator.pot (added)
-
tags/1.9.1/readme.txt (added)
-
tags/1.9.1/siculotech-url-domain-migrator.php (added)
-
trunk/languages/siculotech-url-domain-migrator-es_ES.mo (modified) ( previous)
-
trunk/languages/siculotech-url-domain-migrator-es_ES.po (modified) (3 diffs)
-
trunk/languages/siculotech-url-domain-migrator-it_IT.mo (modified) ( previous)
-
trunk/languages/siculotech-url-domain-migrator-it_IT.po (modified) (2 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/siculotech-url-domain-migrator.php (modified) (19 diffs)
Legend:
- Unmodified
- Added
- Removed
-
siculotech-url-domain-migrator/trunk/languages/siculotech-url-domain-migrator-es_ES.po
r3788215 r3790778 1 1 msgid "" 2 2 msgstr "" 3 "Project-Id-Version: Siculotech URL & Domain Migrator 1. 8\n"3 "Project-Id-Version: Siculotech URL & Domain Migrator 1.9\n" 4 4 "Report-Msgid-Bugs-To: \n" 5 "POT-Creation-Date: 2026-1 0-2712:00+0000\n"6 "PO-Revision-Date: 2026-1 0-2712:00+0100\n"5 "POT-Creation-Date: 2026-11-08 12:00+0000\n" 6 "PO-Revision-Date: 2026-11-08 12:00+0100\n" 7 7 "Last-Translator: Siculotech\n" 8 8 "Language-Team: Spanish\n" … … 24 24 msgstr "Herramienta profesional para la migración masiva o específica de dominios y enlaces de afiliados nativos de WooCommerce." 25 25 26 msgid "Enjoying this plugin? Feel free to buy me a coffee to support ongoing development." 27 msgstr "¿Te gusta este plugin? Apoya el desarrollo continuo e invítanos a un café." 28 29 msgid "Buy a Coffee (PayPal)" 30 msgstr "Donar con PayPal" 31 26 32 msgid "Guide and Features Explanation" 27 33 msgstr "Guía y explicación de funciones" … … 256 262 257 263 msgid "License activated successfully." 258 msgstr "Licencia activa ta con éxito."264 msgstr "Licencia activada con éxito." 259 265 260 266 msgid "Invalid or already used license key." -
siculotech-url-domain-migrator/trunk/languages/siculotech-url-domain-migrator-it_IT.po
r3788215 r3790778 1 1 msgid "" 2 2 msgstr "" 3 "Project-Id-Version: Siculotech URL & Domain Migrator 1. 8\n"3 "Project-Id-Version: Siculotech URL & Domain Migrator 1.9\n" 4 4 "Report-Msgid-Bugs-To: \n" 5 "POT-Creation-Date: 2026-1 0-2712:00+0000\n"6 "PO-Revision-Date: 2026-1 0-2712:00+0100\n"5 "POT-Creation-Date: 2026-11-08 12:00+0000\n" 6 "PO-Revision-Date: 2026-11-08 12:00+0100\n" 7 7 "Last-Translator: Siculotech\n" 8 8 "Language-Team: Italian\n" … … 24 24 msgstr "Strumento professionale per la migrazione massiva o mirata di domini e link di affiliazione nativi WooCommerce." 25 25 26 msgid "Enjoying this plugin? Feel free to buy me a coffee to support ongoing development." 27 msgstr "Ti piace questo plugin? Supporta lo sviluppo continuo e offrici un caffè." 28 29 msgid "Buy a Coffee (PayPal)" 30 msgstr "Dona con PayPal" 31 26 32 msgid "Guide and Features Explanation" 27 33 msgstr "Guida e Spiegazione Funzionalità" -
siculotech-url-domain-migrator/trunk/readme.txt
r3789209 r3790778 4 4 Requires at least: 5.8 5 5 Tested up to: 7.1 6 Stable tag: 1.9 6 Stable tag: 1.9.1 7 7 License: GPLv2 or later 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
siculotech-url-domain-migrator/trunk/siculotech-url-domain-migrator.php
r3789209 r3790778 3 3 * Plugin Name: Siculotech URL & Domain Migrator 4 4 * Description: Universal plugin for migrating and verifying domains and affiliate links in WooCommerce (_product_url), with domain anti-URL protection, dynamic batches, and secure HTTP verification. 5 * Version: 1.9 5 * Version: 1.9.1 6 6 * Author: Siculotech 7 7 * License: GPLv2 or later … … 15 15 } 16 16 17 // Carica il dominio di traduzione (Text Domain) 18 add_action('plugins_loaded', 'siculotech_migrator_load_textdomain'); 19 function siculotech_migrator_load_textdomain() { 20 load_plugin_textdomain('siculotech-url-domain-migrator', false, dirname(plugin_basename(__FILE__)) . '/languages'); 21 } 22 23 // 1. Registrazione e caricamento degli script esterni 17 // ----------------------------------------------------------------------------- 18 // ENQUEUE 19 // ----------------------------------------------------------------------------- 24 20 add_action('admin_enqueue_scripts', 'siculotech_migrator_enqueue_assets'); 25 21 function siculotech_migrator_enqueue_assets($hook) { … … 32 28 plugins_url('assets/js/migrator.js', __FILE__), 33 29 array('jquery'), 34 ' 1.8',30 '2.1', 35 31 true 36 32 ); … … 64 60 } 65 61 66 // 2. Menu Amministrazione 62 // ----------------------------------------------------------------------------- 63 // MENU 64 // ----------------------------------------------------------------------------- 67 65 add_action('admin_menu', 'siculotech_migrator_menu'); 68 66 function siculotech_migrator_menu() { … … 77 75 } 78 76 79 // 3. Interfaccia Amministrazione HTML (Senza blocchi di licenza) 77 // ----------------------------------------------------------------------------- 78 // PAGINA ADMIN 79 // ----------------------------------------------------------------------------- 80 80 function siculotech_migrator_page_html() { 81 81 if (!current_user_can('manage_options')) { … … 91 91 <h1>🛠️ <?php echo esc_html__('Siculotech URL & Domain Migrator', 'siculotech-url-domain-migrator'); ?></h1> 92 92 <p><?php echo esc_html__('Professional tool for mass or targeted migration of domains and native WooCommerce affiliate links.', 'siculotech-url-domain-migrator'); ?></p> 93 94 <!-- BOX AVVISI E SPIEGAZIONE FUNZIONI --> 93 94 <div style="background: #fff; border: 1px solid #ccd0d4; padding: 10px 15px; margin: 15px 0 20px 0; border-radius: 4px; display: flex; align-items: center; justify-content: space-between; max-width: 800px; box-shadow: 0 1px 3px rgba(0,0,0,0.05);"> 95 <div style="font-size: 13px; color: #3c434a;"> 96 ☕ <?php echo esc_html__('Enjoying this plugin? Feel free to buy me a coffee to support ongoing development.', 'siculotech-url-domain-migrator'); ?> 97 </div> 98 <div> 99 <a href="https://www.paypal.com/donate/?hosted_button_id=KUQ9HZYYRM7NC" target="_blank" style="text-decoration: none; display: inline-flex; align-items: center; background: #ffc439; color: #111; padding: 5px 12px; border-radius: 4px; font-weight: 600; font-size: 12px; border: 1px solid #e0b030; box-shadow: 0 1px 2px rgba(0,0,0,0.1);"> 100 <span style="margin-right: 5px;">☕</span> <?php echo esc_html__('Buy a Coffee (PayPal)', 'siculotech-url-domain-migrator'); ?> 101 </a> 102 </div> 103 </div> 104 95 105 <div class="notice notice-warning inline" style="padding: 12px; margin: 15px 0; border-left: 4px solid #dba617;"> 96 106 <h3 style="margin-top: 0; color: #856404;">⚠️ <?php echo esc_html__('Guide and Features Explanation', 'siculotech-url-domain-migrator'); ?></h3> … … 141 151 <div style="margin-bottom: 4px;"> 142 152 <label style="cursor: pointer;"> 143 <input type="checkbox" class="product-cat-checkbox" value="<?php echo esc_attr($cat->term_id); ?>"> 153 <input type="checkbox" class="product-cat-checkbox" value="<?php echo esc_attr($cat->term_id); ?>"> 144 154 <?php echo esc_html($cat->name); ?> (<?php echo esc_html($cat->count); ?>) 145 155 </label> … … 194 204 </tr> 195 205 </table> 196 206 197 207 <p class="submit" style="display: flex; gap: 10px; align-items: center;"> 198 208 <button type="button" id="start-migration-btn" class="button button-primary button-hero">▶ <?php echo esc_html__('Start Scan and Migration', 'siculotech-url-domain-migrator'); ?></button> … … 227 237 } 228 238 239 // ----------------------------------------------------------------------------- 240 // UTILITY 241 // ----------------------------------------------------------------------------- 242 243 function siculotech_verify_ajax_request() { 244 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- verification happens here. 245 $nonce = isset($_POST['security']) ? sanitize_text_field(wp_unslash($_POST['security'])) : ''; 246 if (!wp_verify_nonce($nonce, 'siculotech_migrator_nonce')) { 247 wp_send_json_error(['message' => __('Security check failed.', 'siculotech-url-domain-migrator')], 403); 248 } 249 if (!current_user_can('manage_options')) { 250 wp_send_json_error(['message' => __('Insufficient permissions.', 'siculotech-url-domain-migrator')], 403); 251 } 252 } 253 229 254 function siculotech_sanitize_domain_input($domain) { 230 $domain = trim( $domain);255 $domain = trim((string) $domain); 231 256 $domain = preg_replace('#^https?://(www\.)?#i', '', $domain); 232 257 $domain = explode('/', $domain)[0]; … … 234 259 } 235 260 236 // 4. AJAX: Calcolo totale prodotti 261 function siculotech_get_post_text($key, $default = '') { 262 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified by caller. 263 if (!isset($_POST[$key])) { 264 return $default; 265 } 266 // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 267 return sanitize_text_field(wp_unslash($_POST[$key])); 268 } 269 270 function siculotech_get_post_int($key, $default = 0) { 271 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified by caller. 272 if (!isset($_POST[$key])) { 273 return $default; 274 } 275 // phpcs:ignore WordPress.Security.NonceVerification.Missing 276 return intval(wp_unslash($_POST[$key])); 277 } 278 279 function siculotech_get_meta_keys_from_post() { 280 $raw = siculotech_get_post_text('meta_keys', ''); 281 if (empty($raw)) { 282 return ['_product_url']; 283 } 284 $keys = array_map('trim', explode(',', $raw)); 285 return array_values(array_filter($keys)); 286 } 287 288 function siculotech_get_categories_from_post() { 289 // phpcs:ignore WordPress.Security.NonceVerification.Missing -- nonce verified by caller. 290 if (!isset($_POST['categories']) || !is_array($_POST['categories'])) { 291 return []; 292 } 293 // phpcs:ignore WordPress.Security.NonceVerification.Missing, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized 294 return array_map('absint', wp_unslash($_POST['categories'])); 295 } 296 297 /** 298 * Restituisce una stringa SQL "IN (...)" con VALORI già quotati/sicuri, 299 * usando esc_sql() sui singoli valori (già sanitizzati a monte). 300 * Niente $wpdb->prepare() → niente warning ReplacementsWrongNumber. 301 */ 302 function siculotech_build_in_list_string($values, $type = 'string') { 303 if (empty($values)) { 304 return "''"; 305 } 306 $parts = []; 307 foreach ($values as $v) { 308 if ($type === 'int') { 309 $parts[] = (string) absint($v); 310 } else { 311 // esc_sql su stringa già sanitizzata 312 $parts[] = "'" . esc_sql((string) $v) . "'"; 313 } 314 } 315 return implode(',', $parts); 316 } 317 318 // ----------------------------------------------------------------------------- 319 // AJAX: TOTAL 320 // ----------------------------------------------------------------------------- 237 321 add_action('wp_ajax_siculotech_migrator_get_total', 'siculotech_migrator_get_total_callback'); 238 322 function siculotech_migrator_get_total_callback() { 239 check_ajax_referer('siculotech_migrator_nonce', 'security');323 siculotech_verify_ajax_request(); 240 324 241 325 global $wpdb; 242 326 243 $old_domain = siculotech_sanitize_domain_input($_POST['old_domain']); 244 $raw_meta = sanitize_text_field($_POST['meta_keys']); 245 $meta_keys = !empty($raw_meta) ? array_map('trim', explode(',', $raw_meta)) : ['_product_url']; 246 $target_ids = sanitize_text_field($_POST['target_ids']); 247 $categories = isset($_POST['categories']) ? array_map('intval', $_POST['categories']) : []; 327 $old_domain = siculotech_sanitize_domain_input(siculotech_get_post_text('old_domain')); 328 $meta_keys = siculotech_get_meta_keys_from_post(); 329 $target_ids = siculotech_get_post_text('target_ids'); 330 $categories = siculotech_get_categories_from_post(); 248 331 249 332 if (empty($old_domain)) { … … 251 334 } 252 335 253 $ placeholders = implode(',', array_fill(0, count($meta_keys), '%s'));254 $ sql_params = array_merge($meta_keys);336 $meta_in = siculotech_build_in_list_string($meta_keys, 'string'); 337 $like = '%' . $wpdb->esc_like($old_domain) . '%'; 255 338 256 339 $has_categories = !empty($categories); … … 258 341 259 342 if ($has_categories && $has_target_ids) { 260 $cat_ids = array_map('intval', $categories); 261 $cat_placeholders = implode(',', array_fill(0, count($cat_ids), '%d')); 262 $ids_array = array_map('intval', explode(',', $target_ids)); 263 $ids_placeholders = implode(',', array_fill(0, count($ids_array), '%d')); 264 265 $sql_params = array_merge($sql_params, $cat_ids, $cat_ids, $ids_array); 266 $sql_params[] = '%' . $old_domain . '%'; 267 268 $total = $wpdb->get_var($wpdb->prepare(" 269 SELECT COUNT(DISTINCT p.ID) 270 FROM {$wpdb->posts} p 271 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 272 WHERE pm.meta_key IN ($placeholders) 273 AND p.ID IN ( 274 SELECT object_id FROM {$wpdb->term_relationships} tr 275 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 276 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 277 UNION 278 SELECT post_parent FROM {$wpdb->posts} pr 279 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 280 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 281 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 282 ) 283 AND p.ID IN ($ids_placeholders) 284 AND pm.meta_value LIKE %s 285 ", $sql_params)); 343 $ids_array = array_values(array_filter(array_map('intval', explode(',', $target_ids)))); 344 $cat_in = siculotech_build_in_list_string($categories, 'int'); 345 $ids_in = siculotech_build_in_list_string($ids_array, 'int'); 346 347 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 348 $total = $wpdb->get_var( 349 $wpdb->prepare( 350 "SELECT COUNT(DISTINCT p.ID) 351 FROM {$wpdb->posts} p 352 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 353 WHERE pm.meta_key IN ($meta_in) 354 AND p.ID IN ( 355 SELECT object_id FROM {$wpdb->term_relationships} tr 356 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 357 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 358 UNION 359 SELECT post_parent FROM {$wpdb->posts} pr 360 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 361 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 362 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 363 ) 364 AND p.ID IN ($ids_in) 365 AND pm.meta_value LIKE %s", 366 $like 367 ) 368 ); 369 // phpcs:enable 286 370 287 371 } elseif ($has_categories) { 288 $cat_ids = array_map('intval', $categories); 289 $cat_placeholders = implode(',', array_fill(0, count($cat_ids), '%d')); 290 291 $sql_params = array_merge($sql_params, $cat_ids, $cat_ids); 292 $sql_params[] = '%' . $old_domain . '%'; 293 294 $total = $wpdb->get_var($wpdb->prepare(" 295 SELECT COUNT(DISTINCT p.ID) 296 FROM {$wpdb->posts} p 297 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 298 WHERE pm.meta_key IN ($placeholders) 299 AND p.ID IN ( 300 SELECT object_id FROM {$wpdb->term_relationships} tr 301 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 302 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 303 UNION 304 SELECT post_parent FROM {$wpdb->posts} pr 305 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 306 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 307 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 308 ) 309 AND pm.meta_value LIKE %s 310 ", $sql_params)); 372 $cat_in = siculotech_build_in_list_string($categories, 'int'); 373 374 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 375 $total = $wpdb->get_var( 376 $wpdb->prepare( 377 "SELECT COUNT(DISTINCT p.ID) 378 FROM {$wpdb->posts} p 379 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 380 WHERE pm.meta_key IN ($meta_in) 381 AND p.ID IN ( 382 SELECT object_id FROM {$wpdb->term_relationships} tr 383 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 384 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 385 UNION 386 SELECT post_parent FROM {$wpdb->posts} pr 387 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 388 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 389 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 390 ) 391 AND pm.meta_value LIKE %s", 392 $like 393 ) 394 ); 395 // phpcs:enable 311 396 312 397 } elseif ($has_target_ids) { 313 $ids_array = array_map('intval', explode(',', $target_ids)); 314 $ids_placeholders = implode(',', array_fill(0, count($ids_array), '%d')); 315 316 $sql_params = array_merge($sql_params, $ids_array); 317 $sql_params[] = '%' . $old_domain . '%'; 318 319 $total = $wpdb->get_var($wpdb->prepare(" 320 SELECT COUNT(DISTINCT p.ID) 321 FROM {$wpdb->posts} p 322 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 323 WHERE pm.meta_key IN ($placeholders) 324 AND p.ID IN ($ids_placeholders) 325 AND pm.meta_value LIKE %s 326 ", $sql_params)); 398 $ids_array = array_values(array_filter(array_map('intval', explode(',', $target_ids)))); 399 $ids_in = siculotech_build_in_list_string($ids_array, 'int'); 400 401 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 402 $total = $wpdb->get_var( 403 $wpdb->prepare( 404 "SELECT COUNT(DISTINCT p.ID) 405 FROM {$wpdb->posts} p 406 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 407 WHERE pm.meta_key IN ($meta_in) 408 AND p.ID IN ($ids_in) 409 AND pm.meta_value LIKE %s", 410 $like 411 ) 412 ); 413 // phpcs:enable 327 414 328 415 } else { 329 $sql_params[] = '%' . $old_domain . '%'; 330 331 $total = $wpdb->get_var($wpdb->prepare(" 332 SELECT COUNT(DISTINCT p.ID) 333 FROM {$wpdb->posts} p 334 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 335 WHERE pm.meta_key IN ($placeholders) 336 AND pm.meta_value LIKE %s 337 ", $sql_params)); 416 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 417 $total = $wpdb->get_var( 418 $wpdb->prepare( 419 "SELECT COUNT(DISTINCT p.ID) 420 FROM {$wpdb->posts} p 421 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 422 WHERE pm.meta_key IN ($meta_in) 423 AND pm.meta_value LIKE %s", 424 $like 425 ) 426 ); 427 // phpcs:enable 338 428 } 339 429 … … 341 431 } 342 432 343 // 5. AJAX: Elaborazione Batch 433 // ----------------------------------------------------------------------------- 434 // AJAX: BATCH 435 // ----------------------------------------------------------------------------- 344 436 add_action('wp_ajax_siculotech_migrator_process_batch', 'siculotech_migrator_process_batch_callback'); 345 437 function siculotech_migrator_process_batch_callback() { 346 check_ajax_referer('siculotech_migrator_nonce', 'security');438 siculotech_verify_ajax_request(); 347 439 348 440 global $wpdb; 349 441 350 $old_domain = siculotech_sanitize_domain_input($_POST['old_domain']); 351 $new_domain = siculotech_sanitize_domain_input($_POST['new_domain']); 352 353 $raw_meta = sanitize_text_field($_POST['meta_keys']); 354 $meta_keys = !empty($raw_meta) ? array_map('trim', explode(',', $raw_meta)) : ['_product_url']; 355 356 $target_ids = sanitize_text_field($_POST['target_ids']); 357 $categories = isset($_POST['categories']) ? array_map('intval', $_POST['categories']) : []; 358 $offset = intval($_POST['offset']); 359 360 $batch_input = trim($_POST['batch_size']); 442 $old_domain = siculotech_sanitize_domain_input(siculotech_get_post_text('old_domain')); 443 $new_domain = siculotech_sanitize_domain_input(siculotech_get_post_text('new_domain')); 444 445 $meta_keys = siculotech_get_meta_keys_from_post(); 446 $target_ids = siculotech_get_post_text('target_ids'); 447 $categories = siculotech_get_categories_from_post(); 448 $offset = siculotech_get_post_int('offset', 0); 449 450 $batch_input = siculotech_get_post_text('batch_size', '10'); 361 451 $limit = ($batch_input === '') ? 999999 : intval($batch_input); 362 if ($limit <= 0) $limit = 10; 363 364 $timeout = intval($_POST['timeout_val']); 365 if ($timeout <= 0) $timeout = 6; 366 367 $skip_on_timeout = intval($_POST['skip_on_timeout']); 368 $ignore_404 = sanitize_text_field($_POST['ignore_404']); 369 370 $placeholders = implode(',', array_fill(0, count($meta_keys), '%s')); 371 $sql_params = array_merge($meta_keys); 452 if ($limit <= 0) { 453 $limit = 10; 454 } 455 456 $timeout = siculotech_get_post_int('timeout_val', 6); 457 if ($timeout <= 0) { 458 $timeout = 6; 459 } 460 461 $skip_on_timeout = siculotech_get_post_int('skip_on_timeout', 0); 462 $ignore_404 = siculotech_get_post_text('ignore_404', 'yes'); 463 464 $meta_in = siculotech_build_in_list_string($meta_keys, 'string'); 465 $like = '%' . $wpdb->esc_like($old_domain) . '%'; 372 466 373 467 $has_categories = !empty($categories); … … 375 469 376 470 if ($has_categories && $has_target_ids) { 377 $cat_ids = array_map('intval', $categories); 378 $cat_placeholders = implode(',', array_fill(0, count($cat_ids), '%d')); 379 $ids_array = array_map('intval', explode(',', $target_ids)); 380 $ids_placeholders = implode(',', array_fill(0, count($ids_array), '%d')); 381 382 $sql_params = array_merge($sql_params, $cat_ids, $cat_ids, $ids_array); 383 $sql_params[] = '%' . $old_domain . '%'; 384 $sql_params[] = $offset; 385 $sql_params[] = $limit; 386 387 $batch_ids = $wpdb->get_col($wpdb->prepare(" 388 SELECT DISTINCT p.ID 389 FROM {$wpdb->posts} p 390 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 391 WHERE pm.meta_key IN ($placeholders) 392 AND p.ID IN ( 393 SELECT object_id FROM {$wpdb->term_relationships} tr 394 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 395 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 396 UNION 397 SELECT post_parent FROM {$wpdb->posts} pr 398 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 399 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 400 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 401 ) 402 AND p.ID IN ($ids_placeholders) 403 AND pm.meta_value LIKE %s 404 LIMIT %d, %d 405 ", $sql_params)); 471 $ids_array = array_values(array_filter(array_map('intval', explode(',', $target_ids)))); 472 $cat_in = siculotech_build_in_list_string($categories, 'int'); 473 $ids_in = siculotech_build_in_list_string($ids_array, 'int'); 474 475 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 476 $batch_ids = $wpdb->get_col( 477 $wpdb->prepare( 478 "SELECT DISTINCT p.ID 479 FROM {$wpdb->posts} p 480 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 481 WHERE pm.meta_key IN ($meta_in) 482 AND p.ID IN ( 483 SELECT object_id FROM {$wpdb->term_relationships} tr 484 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 485 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 486 UNION 487 SELECT post_parent FROM {$wpdb->posts} pr 488 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 489 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 490 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 491 ) 492 AND p.ID IN ($ids_in) 493 AND pm.meta_value LIKE %s 494 LIMIT %d, %d", 495 $like, $offset, $limit 496 ) 497 ); 498 // phpcs:enable 406 499 407 500 } elseif ($has_categories) { 408 $cat_ids = array_map('intval', $categories); 409 $cat_placeholders = implode(',', array_fill(0, count($cat_ids), '%d')); 410 411 $sql_params = array_merge($sql_params, $cat_ids, $cat_ids); 412 $sql_params[] = '%' . $old_domain . '%'; 413 $sql_params[] = $offset; 414 $sql_params[] = $limit; 415 416 $batch_ids = $wpdb->get_col($wpdb->prepare(" 417 SELECT DISTINCT p.ID 418 FROM {$wpdb->posts} p 419 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 420 WHERE pm.meta_key IN ($placeholders) 421 AND p.ID IN ( 422 SELECT object_id FROM {$wpdb->term_relationships} tr 423 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 424 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 425 UNION 426 SELECT post_parent FROM {$wpdb->posts} pr 427 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 428 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 429 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_placeholders) 430 ) 431 AND pm.meta_value LIKE %s 432 LIMIT %d, %d 433 ", $sql_params)); 501 $cat_in = siculotech_build_in_list_string($categories, 'int'); 502 503 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 504 $batch_ids = $wpdb->get_col( 505 $wpdb->prepare( 506 "SELECT DISTINCT p.ID 507 FROM {$wpdb->posts} p 508 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 509 WHERE pm.meta_key IN ($meta_in) 510 AND p.ID IN ( 511 SELECT object_id FROM {$wpdb->term_relationships} tr 512 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 513 WHERE tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 514 UNION 515 SELECT post_parent FROM {$wpdb->posts} pr 516 INNER JOIN {$wpdb->term_relationships} tr ON pr.ID = tr.object_id 517 INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id 518 WHERE pr.post_type = 'product_variation' AND tt.taxonomy = 'product_cat' AND tt.term_id IN ($cat_in) 519 ) 520 AND pm.meta_value LIKE %s 521 LIMIT %d, %d", 522 $like, $offset, $limit 523 ) 524 ); 525 // phpcs:enable 434 526 435 527 } elseif ($has_target_ids) { 436 $ids_array = array_ map('intval', explode(',', $target_ids));437 $ids_ placeholders = implode(',', array_fill(0, count($ids_array), '%d'));438 439 $sql_params = array_merge($sql_params, $ids_array);440 $ sql_params[] = '%' . $old_domain . '%';441 $sql_params[] = $offset;442 $sql_params[] = $limit;443 444 $batch_ids = $wpdb->get_col($wpdb->prepare("445 SELECT DISTINCT p.ID446 FROM {$wpdb->posts} p447 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id448 WHERE pm.meta_key IN ($placeholders)449 AND p.ID IN ($ids_placeholders)450 AND pm.meta_value LIKE %s451 LIMIT %d, %d452 ", $sql_params));528 $ids_array = array_values(array_filter(array_map('intval', explode(',', $target_ids)))); 529 $ids_in = siculotech_build_in_list_string($ids_array, 'int'); 530 531 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 532 $batch_ids = $wpdb->get_col( 533 $wpdb->prepare( 534 "SELECT DISTINCT p.ID 535 FROM {$wpdb->posts} p 536 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 537 WHERE pm.meta_key IN ($meta_in) 538 AND p.ID IN ($ids_in) 539 AND pm.meta_value LIKE %s 540 LIMIT %d, %d", 541 $like, $offset, $limit 542 ) 543 ); 544 // phpcs:enable 453 545 454 546 } else { 455 $sql_params[] = '%' . $old_domain . '%'; 456 $sql_params[] = $offset; 457 $sql_params[] = $limit; 458 459 $batch_ids = $wpdb->get_col($wpdb->prepare(" 460 SELECT DISTINCT p.ID 461 FROM {$wpdb->posts} p 462 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 463 WHERE pm.meta_key IN ($placeholders) 464 AND pm.meta_value LIKE %s 465 LIMIT %d, %d 466 ", $sql_params)); 547 // phpcs:disable WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQL.NotPrepared, PluginCheck.Security.DirectDB.UnescapedDBParameter 548 $batch_ids = $wpdb->get_col( 549 $wpdb->prepare( 550 "SELECT DISTINCT p.ID 551 FROM {$wpdb->posts} p 552 INNER JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id 553 WHERE pm.meta_key IN ($meta_in) 554 AND pm.meta_value LIKE %s 555 LIMIT %d, %d", 556 $like, $offset, $limit 557 ) 558 ); 559 // phpcs:enable 467 560 } 468 561 … … 471 564 foreach ($batch_ids as $pid) { 472 565 $post = get_post($pid); 473 if (!$post) continue; 566 if (!$post) { 567 continue; 568 } 474 569 475 570 $is_variation = ($post->post_type === 'product_variation'); 476 $parent_id = $is_variation ? $post->post_parent : $pid;571 $parent_id = $is_variation ? $post->post_parent : $pid; 477 572 $parent_product = wc_get_product($parent_id); 478 573 479 574 $title = $parent_product ? $parent_product->get_name() : $post->post_title; 480 575 if ($is_variation) { … … 485 580 foreach ($meta_keys as $meta_key) { 486 581 $valore_meta = get_post_meta($pid, $meta_key, true); 487 if (empty($valore_meta)) continue; 582 if (empty($valore_meta)) { 583 continue; 584 } 488 585 489 586 $righe = array_filter(array_map('trim', explode("\n", $valore_meta))); 490 587 491 588 foreach ($righe as $index => $url_singolo) { 492 if (!filter_var($url_singolo, FILTER_VALIDATE_URL)) continue; 493 if (strpos($url_singolo, $old_domain) === false) continue; 589 if (!filter_var($url_singolo, FILTER_VALIDATE_URL)) { 590 continue; 591 } 592 if (strpos($url_singolo, $old_domain) === false) { 593 continue; 594 } 494 595 495 596 $response = wp_remote_get($url_singolo, [ … … 511 612 $http_code = wp_remote_retrieve_response_code($response); 512 613 } 513 614 514 615 if ($timed_out && $skip_on_timeout) { 515 616 $results[] = [ … … 529 630 } 530 631 531 $is_404 = ($http_code == 404);632 $is_404 = ($http_code == 404); 532 633 $needs_fix = true; 533 634 … … 579 680 580 681 wp_send_json_success([ 581 'results' => $results,682 'results' => $results, 582 683 'processed_count' => count($batch_ids) 583 684 ]);
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)