Plugin Directory

Changeset 3338869


Ignore:
Timestamp:
08/04/2025 10:14:38 AM (8 months ago)
Author:
clonable
Message:

version 2.6.0

Location:
clonable
Files:
124 added
15 edited

Legend:

Unmodified
Added
Removed
  • clonable/trunk/clonable-wp.php

    r3336393 r3338869  
    55Description: Official plugin for improving your clones made with Clonable.
    66Plugin URI: https://kb.clonable.net/en/introduction/getting-started/wordpress#de-clonable-plug-in-downloaden
    7 Version: 2.5.6
     7Version: 2.6.0
    88Author: Clonable BV
    99Author URI: https://www.clonable.net
     
    7777include_once "helpers/Html.php";
    7878include_once "helpers/Functions.php";
     79include_once "helpers/MultiCurrency.php";
    7980
    8081// middleware
     
    114115
    115116define('CLONABLE_NAME', 'Clonable');
    116 define('CLONABLE_VERSION', '2.5.6');
     117define('CLONABLE_VERSION', '2.6.0');
    117118
    118119if (defined('WP_CLI') && WP_CLI) {
  • clonable/trunk/controllers/WoocommerceController.php

    r3280987 r3338869  
    55use Clonable\Helpers\Functions;
    66use Clonable\Helpers\Json;
     7use Clonable\Helpers\MultiCurrency;
    78use Clonable\Models\ClonableWooCommerce;
    89use Clonable\Traits\Validation;
     
    8081        return $this->validate_checkbox($input, ClonableWooCommerce::CURCY_SUPPORT_SETTING);
    8182    }
     83
     84    public function clonable_curcy_currency_override_validate($input) {
     85        if (empty($input)) {
     86            return $input;
     87        }
     88        $old_input = get_option(ClonableWooCommerce::CURCY_SUPPORT_SETTING);
     89        $json_input = Json::handle_input($input);
     90        $available_currencies = MultiCurrency::get_all_currencies();
     91
     92        foreach ($json_input as $custom_currency) {
     93            if (empty($custom_currency->currency) || !in_array($custom_currency->currency, $available_currencies)) {
     94                add_settings_error(ClonableWooCommerce::CURCY_SUPPORT_SETTING, 'err_invalid_domain', "You've entered a currency that was not yet configured via CURCY.");
     95                return $old_input;
     96            }
     97        }
     98
     99        if (empty($json_input)) {
     100            return null;
     101        }
     102        return Json::handle_output(json_encode($json_input));
     103    }
    82104}
  • clonable/trunk/helpers/Locales.php

    r3100441 r3338869  
    88    public static function get_display_name($locale) {
    99        return self::get_locale_attribute($locale, 'display_name');
     10    }
     11
     12    public static function get_display_region($locale) {
     13        $display_name = self::get_locale_attribute($locale, 'display_name');
     14        if (preg_match('/\(([^)]+)\)/', $display_name, $matches)) {
     15            return $matches[1];
     16        }
     17        return $display_name;
    1018    }
    1119
  • clonable/trunk/models/ClonableWooCommerce.php

    r3280987 r3338869  
    22
    33namespace Clonable\Models;
     4
     5use Clonable\Helpers\Locales;
     6use Clonable\Helpers\MultiCurrency;
     7use Clonable\Services\MultiCurrencyService;
    48
    59class ClonableWooCommerce {
     
    711
    812    const CURCY_SUPPORT_SETTING = "clonable_enable_curcy_plugin_support";
     13    const CURCY_CURRENCY_OVERRIDES = "clonable_curcy_currency_override";
    914
    1015    public static $fields = [
     
    3641            "name" => "Enable CURCY support",
    3742            "setting" => self::CURCY_SUPPORT_SETTING,
     43        ],
     44        self::CURCY_CURRENCY_OVERRIDES => [
     45            "render" => "clonable_curcy_currency_override_field",
     46            "name" => "Override CURCY currencies",
     47            "setting" => self::CURCY_CURRENCY_OVERRIDES,
     48            "description" => "Override the default currencies that are assigned to a Clonable language."
    3849        ]
    3950    ];
     51
     52    /**
     53     * Get the default values that are used in the MultiCurrency module.
     54     * These by default map the target region of a clone to the local currency.
     55     *
     56     * @return array
     57     */
     58    public static function get_default_currencies(): array {
     59        $response = get_option("clonable_site");
     60        if (empty($response)) {
     61            return array();
     62        }
     63
     64        $site = new Site($response);
     65        $currency_map = [];
     66        foreach ($site->get_clones() as $clone) {
     67            $split_locale = explode("_", $clone['lang_code']);
     68            $currency_map[] = [
     69                'id' => $clone['id'],
     70                'target_region' => mb_strtolower(end($split_locale)),
     71                'display_region' => Locales::get_display_region($clone['lang_code']),
     72                'currency' => MultiCurrency::get_currency_by_region(end($split_locale)),
     73            ];
     74        }
     75        return $currency_map;
     76    }
    4077}
  • clonable/trunk/readme-da_DK.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-de_DE.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-es_ES.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-fr_FR.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-it_IT.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-nb_NO.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-nl_NL.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35De mogelijkheid toegevoegd om valuta's te overschijven voor specifieke regio's.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme-sv_SE.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/readme.txt

    r3336393 r3338869  
    55Tested up to: 6.8.2
    66Requires PHP: 7.2
    7 Stable tag: 2.5.6
     7Stable tag: 2.6.0
    88License: GPL v2 or later
    99
     
    3232
    3333== Changelog ==
     34v2.6.0
     35Added ability to override currencies for specific target regions.
     36
    3437v2.5.6
    3538Added extra null check for WooCommerce service to resolve issues with the WP-CLI
  • clonable/trunk/services/MultiCurrencyService.php

    r3307078 r3338869  
    33namespace Clonable\Services;
    44
     5use Clonable\Helpers\MultiCurrency;
    56use Clonable\Models\ClonableWooCommerce;
    67use Clonable\Traits\PluginCheck;
     
    5455
    5556    private function get_currency() {
     57        $custom_currencies = get_option(ClonableWooCommerce::CURCY_CURRENCY_OVERRIDES);
    5658        $server_data = $_SERVER;
    5759        $target_region = $server_data['HTTP_CLONABLE_TARGET_REGION'] ?? null;
    5860
    59         if (class_exists('WOOMULTI_CURRENCY_Data')) {
    60             $settings = \WOOMULTI_CURRENCY_Data::get_ins();
    61             if ($target_region !== null) {
    62                 $target_region_upper = strtoupper($target_region);
    63                 return $settings->get_currency_code($target_region_upper);
    64             } else {
    65                 return $settings->get_default_currency();
     61        if (empty($custom_currencies)) {
     62            return MultiCurrency::get_currency_by_region($target_region);
     63        } else {
     64            foreach ($custom_currencies as $currency) {
     65                if ($currency['target_region'] === $target_region) {
     66                    // If a custom currency has been defined, return that one instead of the custom one
     67                    return $currency['currency'];
     68                }
    6669            }
     70            return MultiCurrency::get_currency_by_region($target_region);
    6771        }
    68 
    69         // if the MultiCurrency class does not exist, then return null.
    70         return null;
    7172    }
    7273}
  • clonable/trunk/views/WoocommerceView.php

    r3280987 r3338869  
    33namespace Clonable\Views;
    44
     5use Clonable\Helpers\Functions;
    56use Clonable\Helpers\Html;
     7use Clonable\Helpers\Json;
     8use Clonable\Helpers\MultiCurrency;
     9use Clonable\Helpers\Session;
    610use Clonable\Models\ClonableWooCommerce;
    711use Clonable\Traits\Forms;
     
    1317    public function render()
    1418    {
     19        Html::include_fomantic_dropdown();
    1520        Html::include_alpine();
    1621        $module_enabled = get_option('clonable_woocommerce_module_enabled', 'on') === 'on';
     
    131136        <?php
    132137    }
     138
     139    public function clonable_curcy_currency_override_field() {
     140        $option = Session::old(ClonableWooCommerce::CURCY_CURRENCY_OVERRIDES);
     141        if (empty($option)) {
     142            $default_currencies = ClonableWooCommerce::get_default_currencies();
     143            $option = Json::handle_output(json_encode($default_currencies));
     144        }
     145        $currencies = MultiCurrency::get_all_currencies();
     146
     147        ?>
     148        <p style="max-width: 75%">
     149            By default, Clonable will do a smart selection of the currency based on the locale of your clone.
     150            So let's say you've got the clone en_gb, Clonable by default will use GBP as its currency.
     151            But if you want to use another currency for Great Britain, you can override it in the table below.
     152            <br/>
     153            <strong>Note: Only currencies that are configured in CURCY will be available to select.</strong>
     154        </p>
     155        <div class="wrap">
     156            <div x-data="{ currencies: <?php echo esc_js($option); ?> }">
     157                <!-- hidden input field for submitting the json value -->
     158                <label for="clonable_curcy_currency_override"></label>
     159                <input x-model="JSON.stringify(currencies)" name="clonable_curcy_currency_override"
     160                       id="clonable_curcy_currency_override" style="display: none"/>
     161                <!-- Display data -->
     162                <table class="wp-list-table fat striped" style="width: 75%">
     163                    <thead>
     164                    <tr>
     165                        <th>Target Region</th>
     166                        <th>Currency</th>
     167                    </tr>
     168                    </thead>
     169                    <tbody>
     170                    <template x-for="(currency, index) in currencies" :key="index">
     171                        <tr>
     172                            <input x-model="currencies[index].target_region" type="hidden">
     173                            <td><input disabled x-model="currencies[index].display_region" style="width: 100%"/></td>
     174                            <td>
     175                                <div class="field">
     176                                    <div class="ui search selection dropdown" style="width: 75%">
     177                                        <input x-model="currencies[index].currency" type="hidden">
     178                                        <i class="dropdown icon"></i>
     179                                        <div class="default text mt-0.5"></div>
     180                                        <div class="menu">
     181                                            <?php
     182                                            foreach ($currencies as $currency) {
     183                                                $symbol = get_woocommerce_currency_symbol($currency);
     184                                                echo "<div @click='currencies[index].currency = \"" . esc_attr($currency) . "\"' class='item' data-value='" . esc_attr($currency) . "'>" . esc_html($currency) . " ($symbol)</div>";
     185                                            }
     186                                            ?>
     187                                        </div>
     188                                    </div>
     189                                </div>
     190                            </td>
     191                        </tr>
     192                    </template>
     193                    </tbody>
     194                </table>
     195            </div>
     196        </div>
     197        <?php
     198        // phpcs:enable WordPress.Security.EscapeOutput.OutputNotEscaped
     199        $this->render_error('clonable_woocommerce_allowed_origins');
     200    }
    133201}
Note: See TracChangeset for help on using the changeset viewer.