Plugin Directory

Changeset 3436768


Ignore:
Timestamp:
01/10/2026 06:04:47 PM (3 months ago)
Author:
onodev77
Message:

fix migration keys

Location:
affiliate-amazon-shortcode
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • affiliate-amazon-shortcode/tags/1.5/affiliate-amazon-shortcode.php

    r3436748 r3436768  
    234234        $marketplaces = affiamsh_get_amazon_marketplaces();
    235235        $image_sizes = affiamsh_get_image_sizes();
     236       
     237        // ✅ IMPORTANTE: Carica settings esistenti prima di sovrascrivere
     238        $existing_settings = get_option('affiamsh_plugin_settings', []);
    236239
    237240        $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'] ?? ''),
    244247            // 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'] ?? ''),
    246249            'region' => $marketplaces[$marketplace] ?? 'us-east-1',
    247250            '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'),
    249253            'num_products' => isset($_POST['num_products']) ? absint(wp_unslash($_POST['num_products'])) : 3,
    250254            'num_columns' => isset($_POST['num_columns']) ? absint(wp_unslash($_POST['num_columns'])) : 3,
     
    325329                    <th scope="row">API Version</th>
    326330                    <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                        ?>
    327339                        <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'); ?>>
    329341                                Creators API (OAuth 2.0)
    330342                            </option>
    331                             <option value="paapi5" <?php selected($settings['api_version'] ?? 'creators', 'paapi5'); ?>>
     343                            <option value="paapi5" <?php selected($current_api, 'paapi5'); ?>>
    332344                                PA-API 5.0 (Legacy)
    333345                            </option>
     
    338350               
    339351                <!-- 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;'; ?>">
    341353                    <td colspan="2">
    342354                        <h3 style="margin-bottom: 10px;">🆕 Creators API Credentials (OAuth 2.0)</h3>
     
    344356                    </td>
    345357                </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;'; ?>">
    347359                    <th scope="row">Credential ID (Client ID)</th>
    348360                    <td>
     
    351363                    </td>
    352364                </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;'; ?>">
    354366                    <th scope="row">Credential Secret (Client Secret)</th>
    355367                    <td>
     
    360372               
    361373                <!-- 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;'; ?>">
    363375                    <td colspan="2">
    364376                        <h3 style="margin-bottom: 10px;">PA-API 5.0 Credentials (Legacy)</h3>
     
    366378                    </td>
    367379                </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;'; ?>">
    369381                    <th scope="row">Access Key (PA-API 5.0)</th>
    370382                    <td>
     
    373385                    </td>
    374386                </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;'; ?>">
    376388                    <th scope="row">Secret Key (PA-API 5.0)</th>
    377389                    <td>
  • affiliate-amazon-shortcode/trunk/affiliate-amazon-shortcode.php

    r3436748 r3436768  
    234234        $marketplaces = affiamsh_get_amazon_marketplaces();
    235235        $image_sizes = affiamsh_get_image_sizes();
     236       
     237        // ✅ IMPORTANTE: Carica settings esistenti prima di sovrascrivere
     238        $existing_settings = get_option('affiamsh_plugin_settings', []);
    236239
    237240        $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'] ?? ''),
    244247            // 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'] ?? ''),
    246249            'region' => $marketplaces[$marketplace] ?? 'us-east-1',
    247250            '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'),
    249253            'num_products' => isset($_POST['num_products']) ? absint(wp_unslash($_POST['num_products'])) : 3,
    250254            'num_columns' => isset($_POST['num_columns']) ? absint(wp_unslash($_POST['num_columns'])) : 3,
     
    325329                    <th scope="row">API Version</th>
    326330                    <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                        ?>
    327339                        <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'); ?>>
    329341                                Creators API (OAuth 2.0)
    330342                            </option>
    331                             <option value="paapi5" <?php selected($settings['api_version'] ?? 'creators', 'paapi5'); ?>>
     343                            <option value="paapi5" <?php selected($current_api, 'paapi5'); ?>>
    332344                                PA-API 5.0 (Legacy)
    333345                            </option>
     
    338350               
    339351                <!-- 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;'; ?>">
    341353                    <td colspan="2">
    342354                        <h3 style="margin-bottom: 10px;">🆕 Creators API Credentials (OAuth 2.0)</h3>
     
    344356                    </td>
    345357                </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;'; ?>">
    347359                    <th scope="row">Credential ID (Client ID)</th>
    348360                    <td>
     
    351363                    </td>
    352364                </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;'; ?>">
    354366                    <th scope="row">Credential Secret (Client Secret)</th>
    355367                    <td>
     
    360372               
    361373                <!-- 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;'; ?>">
    363375                    <td colspan="2">
    364376                        <h3 style="margin-bottom: 10px;">PA-API 5.0 Credentials (Legacy)</h3>
     
    366378                    </td>
    367379                </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;'; ?>">
    369381                    <th scope="row">Access Key (PA-API 5.0)</th>
    370382                    <td>
     
    373385                    </td>
    374386                </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;'; ?>">
    376388                    <th scope="row">Secret Key (PA-API 5.0)</th>
    377389                    <td>
Note: See TracChangeset for help on using the changeset viewer.