Plugin Directory

Changeset 3844084


Ignore:
Timestamp:
12/04/2026 09:33:51 AM (less than one hour ago)
Author:
clonable
Message:

Deploy clonable 2.16.0 from Git tag 2.16.0

Location:
clonable
Files:
186 added
15 edited

Legend:

Unmodified
Added
Removed
  • clonable/trunk/assets/js/alpine.js

    r3770773 r3844084  
     1/**
     2 * Keep Fomantic dropdowns in Alpine x-for tables in sync with Alpine data.
     3 */
     4(function () {
     5    const DROPDOWN_SETTINGS = { fullTextSearch: true };
     6    const watched = new WeakSet();
     7
     8    // Get x-model expression of input
     9    function modelExpression(input) {
     10        const attribute = Array.from(input.attributes).find(function (attr) {
     11            return attr.name === 'x-model' || attr.name.startsWith('x-model.');
     12        });
     13        return attribute ? attribute.value : null;
     14    }
     15
     16    function syncDropdowns(container) {
     17        if (!window.jQuery || !jQuery.fn.dropdown) return;
     18
     19        jQuery(container).find('.ui.dropdown').each(function () {
     20            const input = Array.from(this.querySelectorAll('input[type="hidden"]')).find(modelExpression);
     21            if (!input) return; // Not bound to Alpine data
     22
     23            const $dropdown = jQuery(this);
     24            if (!$dropdown.data('module-dropdown')) {
     25                $dropdown.dropdown(DROPDOWN_SETTINGS);
     26            }
     27
     28            const value = Alpine.evaluate(input, modelExpression(input));
     29            const expected = value === null || value === undefined ? '' : String(value);
     30            const shown = $dropdown.find('.menu .item.active').attr('data-value') || '';
     31            if (shown === expected) return;
     32
     33            const hasItem = $dropdown.find('.menu .item').filter(function () {
     34                return this.getAttribute('data-value') === expected;
     35            }).length > 0;
     36
     37            if (expected !== '' && hasItem) {
     38                $dropdown.dropdown('set selected', expected);
     39            } else {
     40                $dropdown.dropdown('clear');
     41            }
     42        });
     43    }
     44
     45    // Observe rows of x-for table, sync once after Alpine changed them.
     46    function watchTable(template) {
     47        const container = template.parentElement;
     48        if (!container || watched.has(container)) return;
     49        watched.add(container);
     50
     51        let pending = false;
     52        new MutationObserver(function () {
     53            if (pending) return;
     54            pending = true;
     55            // Wait until Alpine finished row scopes + bindings.
     56            Alpine.nextTick(function () {
     57                pending = false;
     58                syncDropdowns(container);
     59            });
     60        }).observe(container, { childList: true });
     61
     62        if (window.jQuery) {
     63            jQuery(function () {
     64                syncDropdowns(container);
     65            });
     66        }
     67    }
     68
     69    document.addEventListener('alpine:initialized', function () {
     70        document.querySelectorAll('template[x-for]').forEach(watchTable);
     71    });
     72})();
     73
    174document.addEventListener('alpine:init', () => {
    275    Alpine.data('languageTags', (languageTags) => ({
    … …  
    28101            }
    29102            this.languageTagData.data.clones.push(data);
    30             jQuery(document).ready(function ($) {
    31                 $('.ui.dropdown')
    32                     .dropdown({ fullTextSearch: true })
    33                 ;
    34             })
    35103        },
    36104        removeRow(index) {
    … …  
    48116            }
    49117            this.languages.push(data);
    50             jQuery(document).ready(function ($) {
    51                 $('.ui.dropdown')
    52                     .dropdown({ fullTextSearch: true })
    53                 ;
    54             })
    55118        },
    56119        removeRow(index) {
  • clonable/trunk/clonable-wp.php

    r3823289 r3844084  
    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.15.1
     7Version: 2.16.0
    88Author: Clonable BV
    99Author URI: https://www.clonable.net
    … …  
    3636use Clonable\Services\SearchEngineService;
    3737use Clonable\Services\AdminUIService; // general admin UI service for additions, notices, etc.
     38use Clonable\Services\SupportChatService;
    3839use Clonable\Services\Modules\ExclusionModule;
    3940use Clonable\Services\Modules\TaxonomyModule;
    … …  
    134135require_once 'services/WpRocketCacheService.php';
    135136require_once 'services/AdminUIService.php'; // general admin UI service for additions, notices, etc.
     137require_once 'services/SupportChatService.php';
    136138require_once 'services/EmailTranslationsService.php';
    137139require_once 'services/MigrationService.php';
    … …  
    168170define('CLONABLE_NAME', 'Clonable');
    169171define('CLONABLE_PLUGIN_BASE', plugin_basename(__FILE__));
    170 define('CLONABLE_VERSION', '2.15.1');
     172define('CLONABLE_VERSION', '2.16.0');
    171173define('CLONABLE_URL', plugin_dir_url(__FILE__));
    172174
    … …  
    358360                error_log("[Clonable] Error handling admin UI service: {$exception->getMessage()}");
    359361        }
     362
     363        try {
     364                $support_chat_service = new SupportChatService();
     365        } catch (\Throwable $exception) {
     366                error_log("[Clonable] Error handling support chat service: {$exception->getMessage()}");
     367        }
    360368}
  • clonable/trunk/readme-da_DK.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-de_DE.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37
     38Some small CMS area bugfixes
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-es_ES.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-fr_FR.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-it_IT.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-nb_NO.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-nl_NL.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme-sv_SE.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/readme.txt

    r3823289 r3844084  
    55Tested up to: 7.1
    66Requires PHP: 8.1
    7 Stable tag: 2.15.1
     7Stable tag: 2.16.0
    88License: GPL v2 or later
    99
    … …  
    3232
    3333== Changelog ==
     34v2.16.0
     35Support chatbox inclusion on the Clonable settings pages within WordPress admin
     36Syncing with Clonable no longer re-adds languages removed from the language switcher
     37Some small CMS area bugfixes
     38Language switcher bugfix
     39
    3440v2.15.1
    3541Language switcher stylesheet modifications
  • clonable/trunk/services/LanguageSwitcherService.php

    r3823289 r3844084  
    810810                }
    811811
    812                 $clones                = $site->get_clones();
    813812                $locally_set_languages = $this->get_locally_set_languages();
     813                $clones                = self::clones_in_table($site->get_clones(), $locally_set_languages);
    814814
    815815                // Source URL is never translated; keep it out of the batch.
    … …  
    925925
    926926        /**
     927         * Clones the language switcher shows. Language switcher CMS table leads: clone not in this table (by lang_code) is hidden.
     928         * @param array $clones                Clones from the site, keyed by clone index.
     929         * @param array $locally_set_languages Switcher table rows (stdClass).
     930         * @return array
     931         */
     932        private static function clones_in_table(array $clones, array $locally_set_languages): array {
     933                $table_codes = array_filter(array_map('strval', array_column($locally_set_languages, 'clonableLocaleCode')), 'strlen');
     934                if (!$table_codes) {
     935                        return $clones;
     936                }
     937
     938                $visible = [];
     939                foreach ($clones as $index => $clone) {
     940                        if (in_array( (string) ( $clone['lang_code'] ?? '' ), $table_codes, true)) {
     941                                $visible[$index] = $clone;
     942                        }
     943                }
     944
     945                return $visible;
     946        }
     947
     948        /**
    927949         * Normalise a URL for comparison: ignore the "www." prefix and a trailing slash.
    928950         */
  • clonable/trunk/services/SyncService.php

    r3719175 r3844084  
    1212
    1313class SyncService {
     14        private const SYNCED_SWITCHER_URLS = 'clonable_langswitch_synced_urls';
     15
    1416        public function sync_site() {
    1517                // Reset connectivity check
    … …  
    3335                        $this->sync_woocommerce($site->get_domain());
    3436
     37                        $this->init_synced_switcher_urls($site);
    3538                        $this->sync_language_switcher($site->get_locale(), Locales::get_display_name($site->get_locale()), $site->get_url());
    3639                        foreach ($site->get_clones() as $index => $clone) {
    … …  
    118121        }
    119122
     123        /**
     124         * Add language to switcher once per URL. Languages removed by CMS user stay removed.
     125         * No escapes: view esc_js() strips backslashes.
     126         *
     127         * @link https://developer.wordpress.org/reference/functions/get_option/
     128         * @link https://developer.wordpress.org/reference/functions/update_option/
     129         * @link https://developer.wordpress.org/reference/functions/wp_json_encode/
     130         *
     131         * @param string $locale       Locale code.
     132         * @param string $display_name Language name.
     133         * @param string $url          Site or clone URL.
     134         */
    120135        public function sync_language_switcher($locale, $display_name, $url) {
    121                 $language_switcher_items = get_option('clonable_langswitch_data');
    122                 if (empty($language_switcher_items)) {
    123                         $language_switcher_items = '[]';
    124                 }
    125 
    126                 /* @var array $languages */
    127                 $languages = Json::handle_input($language_switcher_items);
    128                 // if value is not yet in array, then you can put it in.
    129                 if (!in_array($url, array_column($languages, 'clonableUrl'))) {
     136                $synced = get_option(self::SYNCED_SWITCHER_URLS, []);
     137                $synced = is_array($synced) ? $synced : [];
     138                if (in_array($url, $synced, true)) {
     139                        return;
     140                }
     141
     142                $languages = Json::decode_array(get_option('clonable_langswitch_data', '[]'));
     143                if (!in_array($url, array_column($languages, 'clonableUrl'), true)) {
    130144                        $languages[] = [
    131145                                'clonableLocaleCode'      => $locale,
    … …  
    133147                                'clonableUrl'             => $url,
    134148                        ];
    135                 }
    136 
    137                 $languages = Json::handle_output(json_encode($languages));
    138                 update_option('clonable_langswitch_data', $languages, true);
     149
     150                        $encoded = wp_json_encode($languages, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     151                        if (!is_string($encoded)) {
     152                                return;
     153                        }
     154                        update_option('clonable_langswitch_data', $encoded, true);
     155                }
     156
     157                $synced[] = $url;
     158                update_option(self::SYNCED_SWITCHER_URLS, $synced, false);
     159        }
     160
     161        /**
     162         * Synced before this option existed: mark site + clone URLs as synced, add nothing.
     163         * Languages removed before the update stay removed.
     164         *
     165         * @link https://developer.wordpress.org/reference/functions/get_option/
     166         * @link https://developer.wordpress.org/reference/functions/update_option/
     167         *
     168         * @param Site $site Site from the API.
     169         */
     170        public function init_synced_switcher_urls(Site $site) {
     171                if (get_option(self::SYNCED_SWITCHER_URLS) !== false || get_option('clonable_last_sync') === false) {
     172                        return;
     173                }
     174
     175                $urls = [$site->get_url()];
     176                foreach (array_keys($site->get_clones()) as $index) {
     177                        $urls[] = $site->get_clone_url($index);
     178                }
     179
     180                update_option(self::SYNCED_SWITCHER_URLS, $urls, false);
    139181        }
    140182
  • clonable/trunk/views/LanguageSwitcherView.php

    r3759957 r3844084  
    164164                        <li>3: The flag is the flag of the country you want the languge switcher to show.</li>
    165165                        <li>4: The text is the text of the language you want to show. For example: "de" or "german".</li>
     166                        <li>5: Removing a clone language here also hides it from the shortcode and menu language switchers. When the table is empty, all clone languages are shown.</li>
    166167                </ul>
    167168                <div class="wrap">
  • clonable/trunk/views/Layout.php

    r3719175 r3844084  
    1111use Clonable\Objects\Notification;
    1212use Clonable\Routes\Router;
     13use Clonable\Services\SupportChatService;
    1314use Throwable;
    1415
    … …  
    148149                                        <a target="_blank" href="https://www.youtube.com/@clonable">YouTube channel.</a>
    149150                                </p>
     151                                <?php
     152                                try {
     153                                        SupportChatService::render_button();
     154                                } catch (Throwable $throwable) {
     155                                        error_log("[Clonable] Error rendering support chat button: {$throwable->getMessage()}");
     156                                }
     157                                ?>
    150158                        </div>
    151159                <?php
Note: See TracChangeset for help on using the changeset viewer.