Changeset 3436768
- Timestamp:
- 01/10/2026 06:04:47 PM (3 months ago)
- Location:
- affiliate-amazon-shortcode
- Files:
-
- 2 edited
-
tags/1.5/affiliate-amazon-shortcode.php (modified) (8 diffs)
-
trunk/affiliate-amazon-shortcode.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
affiliate-amazon-shortcode/tags/1.5/affiliate-amazon-shortcode.php
r3436748 r3436768 234 234 $marketplaces = affiamsh_get_amazon_marketplaces(); 235 235 $image_sizes = affiamsh_get_image_sizes(); 236 237 // ✅ IMPORTANTE: Carica settings esistenti prima di sovrascrivere 238 $existing_settings = get_option('affiamsh_plugin_settings', []); 236 239 237 240 $settings = [ 238 // Credenziali PA-API 5.0 (Legacy) 239 'access_key_paapi5' => isset($_POST['access_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['access_key_paapi5'])) : '',240 'secret_key_paapi5' => isset($_POST['secret_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['secret_key_paapi5'])) : '',241 // Credenziali Creators API (OAuth 2.0) 242 'credential_id_creators' => isset($_POST['credential_id_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_id_creators'])) : '',243 'credential_secret_creators' => isset($_POST['credential_secret_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_secret_creators'])) : '',241 // Credenziali PA-API 5.0 (Legacy) - preserva se non nel POST 242 'access_key_paapi5' => isset($_POST['access_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['access_key_paapi5'])) : ($existing_settings['access_key_paapi5'] ?? ''), 243 'secret_key_paapi5' => isset($_POST['secret_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['secret_key_paapi5'])) : ($existing_settings['secret_key_paapi5'] ?? ''), 244 // Credenziali Creators API (OAuth 2.0) - preserva se non nel POST 245 'credential_id_creators' => isset($_POST['credential_id_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_id_creators'])) : ($existing_settings['credential_id_creators'] ?? ''), 246 'credential_secret_creators' => isset($_POST['credential_secret_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_secret_creators'])) : ($existing_settings['credential_secret_creators'] ?? ''), 244 247 // Impostazioni comuni 245 'partner_tag' => isset($_POST['partner_tag']) ? sanitize_text_field(wp_unslash($_POST['partner_tag'])) : '',248 'partner_tag' => isset($_POST['partner_tag']) ? sanitize_text_field(wp_unslash($_POST['partner_tag'])) : ($existing_settings['partner_tag'] ?? ''), 246 249 'region' => $marketplaces[$marketplace] ?? 'us-east-1', 247 250 'marketplace' => $marketplace, 248 'api_version' => isset($_POST['api_version']) ? sanitize_text_field(wp_unslash($_POST['api_version'])) : 'creators', 251 // ✅ IMPORTANTE: Preserva api_version esistente se non nel POST 252 'api_version' => isset($_POST['api_version']) ? sanitize_text_field(wp_unslash($_POST['api_version'])) : ($existing_settings['api_version'] ?? 'paapi5'), 249 253 'num_products' => isset($_POST['num_products']) ? absint(wp_unslash($_POST['num_products'])) : 3, 250 254 'num_columns' => isset($_POST['num_columns']) ? absint(wp_unslash($_POST['num_columns'])) : 3, … … 325 329 <th scope="row">API Version</th> 326 330 <td> 331 <?php 332 // ✅ Default intelligente per backward compatibility 333 // Se esistono credenziali PA-API 5.0 → default 'paapi5' 334 // Altrimenti → default 'creators' 335 $has_paapi5 = !empty($settings['access_key_paapi5']) || !empty($settings['access_key']); 336 $default_api = $has_paapi5 ? 'paapi5' : 'creators'; 337 $current_api = $settings['api_version'] ?? $default_api; 338 ?> 327 339 <select name="api_version" id="affiamsh_api_version" class="regular-text" onchange="affiamsh_toggle_credentials()"> 328 <option value="creators" <?php selected($ settings['api_version'] ?? 'creators', 'creators'); ?>>340 <option value="creators" <?php selected($current_api, 'creators'); ?>> 329 341 Creators API (OAuth 2.0) 330 342 </option> 331 <option value="paapi5" <?php selected($ settings['api_version'] ?? 'creators', 'paapi5'); ?>>343 <option value="paapi5" <?php selected($current_api, 'paapi5'); ?>> 332 344 PA-API 5.0 (Legacy) 333 345 </option> … … 338 350 339 351 <!-- Creators API Credentials (OAuth 2.0) --> 340 <tr id="affiamsh_creators_section" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'creators' ? '' : 'display:none;'; ?>">352 <tr id="affiamsh_creators_section" style="<?php echo $current_api === 'creators' ? '' : 'display:none;'; ?>"> 341 353 <td colspan="2"> 342 354 <h3 style="margin-bottom: 10px;">🆕 Creators API Credentials (OAuth 2.0)</h3> … … 344 356 </td> 345 357 </tr> 346 <tr id="affiamsh_creators_credential_id" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'creators' ? '' : 'display:none;'; ?>">358 <tr id="affiamsh_creators_credential_id" style="<?php echo $current_api === 'creators' ? '' : 'display:none;'; ?>"> 347 359 <th scope="row">Credential ID (Client ID)</th> 348 360 <td> … … 351 363 </td> 352 364 </tr> 353 <tr id="affiamsh_creators_credential_secret" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'creators' ? '' : 'display:none;'; ?>">365 <tr id="affiamsh_creators_credential_secret" style="<?php echo $current_api === 'creators' ? '' : 'display:none;'; ?>"> 354 366 <th scope="row">Credential Secret (Client Secret)</th> 355 367 <td> … … 360 372 361 373 <!-- PA-API 5.0 Credentials --> 362 <tr id="affiamsh_paapi5_section" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'paapi5' ? '' : 'display:none;'; ?>">374 <tr id="affiamsh_paapi5_section" style="<?php echo $current_api === 'paapi5' ? '' : 'display:none;'; ?>"> 363 375 <td colspan="2"> 364 376 <h3 style="margin-bottom: 10px;">PA-API 5.0 Credentials (Legacy)</h3> … … 366 378 </td> 367 379 </tr> 368 <tr id="affiamsh_paapi5_access_key" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'paapi5' ? '' : 'display:none;'; ?>">380 <tr id="affiamsh_paapi5_access_key" style="<?php echo $current_api === 'paapi5' ? '' : 'display:none;'; ?>"> 369 381 <th scope="row">Access Key (PA-API 5.0)</th> 370 382 <td> … … 373 385 </td> 374 386 </tr> 375 <tr id="affiamsh_paapi5_secret_key" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'paapi5' ? '' : 'display:none;'; ?>">387 <tr id="affiamsh_paapi5_secret_key" style="<?php echo $current_api === 'paapi5' ? '' : 'display:none;'; ?>"> 376 388 <th scope="row">Secret Key (PA-API 5.0)</th> 377 389 <td> -
affiliate-amazon-shortcode/trunk/affiliate-amazon-shortcode.php
r3436748 r3436768 234 234 $marketplaces = affiamsh_get_amazon_marketplaces(); 235 235 $image_sizes = affiamsh_get_image_sizes(); 236 237 // ✅ IMPORTANTE: Carica settings esistenti prima di sovrascrivere 238 $existing_settings = get_option('affiamsh_plugin_settings', []); 236 239 237 240 $settings = [ 238 // Credenziali PA-API 5.0 (Legacy) 239 'access_key_paapi5' => isset($_POST['access_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['access_key_paapi5'])) : '',240 'secret_key_paapi5' => isset($_POST['secret_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['secret_key_paapi5'])) : '',241 // Credenziali Creators API (OAuth 2.0) 242 'credential_id_creators' => isset($_POST['credential_id_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_id_creators'])) : '',243 'credential_secret_creators' => isset($_POST['credential_secret_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_secret_creators'])) : '',241 // Credenziali PA-API 5.0 (Legacy) - preserva se non nel POST 242 'access_key_paapi5' => isset($_POST['access_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['access_key_paapi5'])) : ($existing_settings['access_key_paapi5'] ?? ''), 243 'secret_key_paapi5' => isset($_POST['secret_key_paapi5']) ? sanitize_text_field(wp_unslash($_POST['secret_key_paapi5'])) : ($existing_settings['secret_key_paapi5'] ?? ''), 244 // Credenziali Creators API (OAuth 2.0) - preserva se non nel POST 245 'credential_id_creators' => isset($_POST['credential_id_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_id_creators'])) : ($existing_settings['credential_id_creators'] ?? ''), 246 'credential_secret_creators' => isset($_POST['credential_secret_creators']) ? sanitize_text_field(wp_unslash($_POST['credential_secret_creators'])) : ($existing_settings['credential_secret_creators'] ?? ''), 244 247 // Impostazioni comuni 245 'partner_tag' => isset($_POST['partner_tag']) ? sanitize_text_field(wp_unslash($_POST['partner_tag'])) : '',248 'partner_tag' => isset($_POST['partner_tag']) ? sanitize_text_field(wp_unslash($_POST['partner_tag'])) : ($existing_settings['partner_tag'] ?? ''), 246 249 'region' => $marketplaces[$marketplace] ?? 'us-east-1', 247 250 'marketplace' => $marketplace, 248 'api_version' => isset($_POST['api_version']) ? sanitize_text_field(wp_unslash($_POST['api_version'])) : 'creators', 251 // ✅ IMPORTANTE: Preserva api_version esistente se non nel POST 252 'api_version' => isset($_POST['api_version']) ? sanitize_text_field(wp_unslash($_POST['api_version'])) : ($existing_settings['api_version'] ?? 'paapi5'), 249 253 'num_products' => isset($_POST['num_products']) ? absint(wp_unslash($_POST['num_products'])) : 3, 250 254 'num_columns' => isset($_POST['num_columns']) ? absint(wp_unslash($_POST['num_columns'])) : 3, … … 325 329 <th scope="row">API Version</th> 326 330 <td> 331 <?php 332 // ✅ Default intelligente per backward compatibility 333 // Se esistono credenziali PA-API 5.0 → default 'paapi5' 334 // Altrimenti → default 'creators' 335 $has_paapi5 = !empty($settings['access_key_paapi5']) || !empty($settings['access_key']); 336 $default_api = $has_paapi5 ? 'paapi5' : 'creators'; 337 $current_api = $settings['api_version'] ?? $default_api; 338 ?> 327 339 <select name="api_version" id="affiamsh_api_version" class="regular-text" onchange="affiamsh_toggle_credentials()"> 328 <option value="creators" <?php selected($ settings['api_version'] ?? 'creators', 'creators'); ?>>340 <option value="creators" <?php selected($current_api, 'creators'); ?>> 329 341 Creators API (OAuth 2.0) 330 342 </option> 331 <option value="paapi5" <?php selected($ settings['api_version'] ?? 'creators', 'paapi5'); ?>>343 <option value="paapi5" <?php selected($current_api, 'paapi5'); ?>> 332 344 PA-API 5.0 (Legacy) 333 345 </option> … … 338 350 339 351 <!-- Creators API Credentials (OAuth 2.0) --> 340 <tr id="affiamsh_creators_section" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'creators' ? '' : 'display:none;'; ?>">352 <tr id="affiamsh_creators_section" style="<?php echo $current_api === 'creators' ? '' : 'display:none;'; ?>"> 341 353 <td colspan="2"> 342 354 <h3 style="margin-bottom: 10px;">🆕 Creators API Credentials (OAuth 2.0)</h3> … … 344 356 </td> 345 357 </tr> 346 <tr id="affiamsh_creators_credential_id" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'creators' ? '' : 'display:none;'; ?>">358 <tr id="affiamsh_creators_credential_id" style="<?php echo $current_api === 'creators' ? '' : 'display:none;'; ?>"> 347 359 <th scope="row">Credential ID (Client ID)</th> 348 360 <td> … … 351 363 </td> 352 364 </tr> 353 <tr id="affiamsh_creators_credential_secret" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'creators' ? '' : 'display:none;'; ?>">365 <tr id="affiamsh_creators_credential_secret" style="<?php echo $current_api === 'creators' ? '' : 'display:none;'; ?>"> 354 366 <th scope="row">Credential Secret (Client Secret)</th> 355 367 <td> … … 360 372 361 373 <!-- PA-API 5.0 Credentials --> 362 <tr id="affiamsh_paapi5_section" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'paapi5' ? '' : 'display:none;'; ?>">374 <tr id="affiamsh_paapi5_section" style="<?php echo $current_api === 'paapi5' ? '' : 'display:none;'; ?>"> 363 375 <td colspan="2"> 364 376 <h3 style="margin-bottom: 10px;">PA-API 5.0 Credentials (Legacy)</h3> … … 366 378 </td> 367 379 </tr> 368 <tr id="affiamsh_paapi5_access_key" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'paapi5' ? '' : 'display:none;'; ?>">380 <tr id="affiamsh_paapi5_access_key" style="<?php echo $current_api === 'paapi5' ? '' : 'display:none;'; ?>"> 369 381 <th scope="row">Access Key (PA-API 5.0)</th> 370 382 <td> … … 373 385 </td> 374 386 </tr> 375 <tr id="affiamsh_paapi5_secret_key" style="<?php echo ($settings['api_version'] ?? 'creators')=== 'paapi5' ? '' : 'display:none;'; ?>">387 <tr id="affiamsh_paapi5_secret_key" style="<?php echo $current_api === 'paapi5' ? '' : 'display:none;'; ?>"> 376 388 <th scope="row">Secret Key (PA-API 5.0)</th> 377 389 <td>
Note: See TracChangeset
for help on using the changeset viewer.