Plugin Directory

Changeset 2793902


Ignore:
Timestamp:
10/04/2022 08:32:15 AM (4 years ago)
Author:
Daisycon
Message:

Update to 1.6.1

Location:
daisycon-woocommerce-pixel/trunk
Files:
1 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • daisycon-woocommerce-pixel/trunk/README.txt

    r2779968 r2793902  
    5757
    5858== Changelog ==
     59
     60= 1.6.1 =
     61* Updated configuration regarding languages and names
    5962
    6063= 1.6 =
  • daisycon-woocommerce-pixel/trunk/admin/assets/daisycon-woocommerce-admin.js

    r2779968 r2793902  
    33
    44    $(document).ready(function(){
     5        let current_value = 'yes';
     6        let td = null;
     7
     8        // Old code, can probably be removed
    59        $('body').on('click', '#the-list .editinline', function(){
    610            var parent_tr = $(this).closest('tr'),
     
    1418            $daisycon_input.val($daisycon_inline_data.text());
    1519        });
     20
     21        // Check if values are not yet, then hide the next
     22        $('#dc-woocommerce-pixel-form select[name*="daisycon_woocommerce_options[lcc_enabled"]').each(function() {
     23            current_value = $(this).find(':selected').val();
     24
     25            if ('yes' !== current_value) {
     26
     27                td = $(this).parent().parent().next().find('td');
     28
     29                td.find('input').hide();
     30                td.append('<span class="daisycon_not_available">-</span>');
     31            }
     32        });
     33
     34        // If value gets updated, check what to do
     35        $('#dc-woocommerce-pixel-form select[name*="daisycon_woocommerce_options[lcc_enabled"]').on('change', function() {
     36            current_value = $(this).find(':selected').val();
     37            td = $(this).parent().parent().next().find('td');
     38
     39            if ('yes' !== current_value && 0 === td.find('.daisycon_not_available').length) {
     40
     41                td.find('input').hide();
     42                td.append('<span class="daisycon_not_available">-</span>');
     43            }
     44            else if ('yes' === current_value) {
     45                td.find('input').show();
     46                td.find('.daisycon_not_available').remove();
     47            }
     48        });
     49
    1650    });
    1751
  • daisycon-woocommerce-pixel/trunk/admin/class-daisycon-woocommerce-settings.php

    r2779968 r2793902  
    7373     * @var      array $setting_fields The required setting fields of this plugin.
    7474     */
    75     protected $required_settings = ['campaign_id', 'daisycon_matching_domain', 'daisycon_commission_vat'];
     75    protected $required_settings = ['campaign_id', 'matching_domain', 'lcc_enabled', 'commission_vat'];
    7676
    7777    /**
     
    146146        }
    147147
    148         printf('<div class="notice notice-%1$s is-dismissible"><p>%2$s</p></div>', esc_attr($type), esc_html($message));
     148        printf('<div class="notice notice-%1$s is-dismissible"><p>%2$s</p></div>', esc_attr($type), $message);
    149149    }
    150150
     
    156156    protected function _get_setting_fields()
    157157    {
    158         $languages[] = get_locale();
    159         $wpmlLanguages = apply_filters( 'wpml_active_languages', NULL, 'orderby=id&order=desc' ) ?? [];
    160 
    161         if (false === empty($wpmlLanguages))
    162         {
    163             $languages = array_unique(array_merge($languages, array_column($wpmlLanguages, 'default_locale')));
    164         }
     158        $languages = daisycon_languages();
    165159
    166160        if (is_null($this->setting_fields))
     
    197191            ],
    198192            'campaign_id_' . $language             => [
    199                 'title'       => __('Campaign ID (required)', $this->text_domain),
     193                'title'       => __('Campaign ID', $this->text_domain),
    200194                'type'        => 'text',
    201195                'placeholder' => '',
     
    204198                'title'   => __('Matching Domain', $this->text_domain),
    205199                'type'    => 'select',
    206                 'group'   => 'daisycon_matching_domain_' . $language,
     200                'group'   => 'matching_domain_' . $language,
    207201                'options' => [
     202                    ''          => __('Select', $this->text_domain),
    208203                    'at19.net'  => __('at19.net', $this->text_domain),
    209204                    'bdt9.net'  => __('bdt9.net', $this->text_domain),
     
    222217                ],
    223218            ],
    224             'daisycon_lcc_enabled_' . $language    => [
     219            'lcc_enabled_' . $language             => [
    225220                'title'   => __('Use LCC cookie', $this->text_domain),
    226221                'type'    => 'select',
    227                 'group'   => 'daisycon_lcc_enabled_' . $language,
     222                'group'   => 'lcc_enabled_' . $language,
    228223                'options' => [
     224                    ''    => __('Select', $this->text_domain),
    229225                    'no'  => __('No', $this->text_domain),
    230226                    'yes' => __('Yes', $this->text_domain),
    231227                ],
    232228            ],
    233             'daisycon_lcc_url_param_' . $language  => [
     229            'lcc_url_param_' . $language           => [
    234230                'title'   => __(
    235                     'LCC `network` url parameter (?the_configured_parameter_below=daisycon)',
     231                    'LCC network',
    236232                    $this->text_domain
    237233                ),
     
    242238                'title'   => __('Commission VAT', $this->text_domain),
    243239                'type'    => 'select',
    244                 'group'   => 'daisycon_commission_vat_' . $language,
     240                'group'   => 'commission_vat_' . $language,
    245241                'options' => [
     242                    ''     => __('Select', $this->text_domain),
    246243                    'incl' => __('Including VAT', $this->text_domain),
    247244                    'excl' => __('Excluding VAT', $this->text_domain),
     
    290287    {
    291288        $settings = $this->get_settings();
    292         $error_shown = false;
    293289
    294290        if (wp_doing_ajax())
     
    297293        }
    298294
    299         $languages = get_available_languages() ?? [];
    300         $languages[] = get_locale();
    301 
    302         foreach ($languages as $language)
    303         {
     295        foreach (daisycon_languages() as $language)
     296        {
     297            $feedbackNames = $this->_set_admin_settings_fields($language);
     298            $errors = [];
     299
    304300            foreach ($this->required_settings as $required_setting)
    305301            {
    306                 if ($error_shown)
     302                $name = $required_setting . '_' . $language;
     303
     304                // Name as array, so only this name will be checked (and no old configuration names, so force update if old configuration is loaded)
     305                if (true === empty(daisycon_get_setting_value([$name], $settings)))
    307306                {
    308                     continue;
     307                    // Current setting not found, so error the "nice" name of the field that is missing
     308                    $errors[$language][] = $feedbackNames[$name]['title'];
    309309                }
    310 
    311                 $name = $required_setting . '_' . $language;
    312                 $name_old = $required_setting; // using the old name which makes it backwards compatible (before multi language/site)
    313 
    314                 if (!isset($settings[$name]) || (isset($settings[$name]) && empty($settings[$name])))
     310            }
     311
     312            if (false === empty($errors[$language]))
     313            {
     314                $error_text = '';
     315                foreach ($errors[$language] as $error)
    315316                {
    316                     if (!isset($settings[$name_old]) || (isset($settings[$name_old]) && empty($settings[$name_old])))
    317                     {
    318                         // old version bad
    319                         $this->show_admin_notice(
    320                             'error',
    321                             __(
    322                                 'Not all required settings for the Daisycon WooCommerce pixel plugin have been set.',
    323                                 $this->text_domain
    324                             )
    325                         );
    326                     }
    327                     else
    328                     {
    329                         // old version good
    330                         $this->show_admin_notice(
    331                             'warning',
    332                             __(
    333                                 'Required settings for the Daisycon WooCommerce pixel plugin are found, but not correctly saved due an update, please go to the pixel settings and update / save them.',
    334                                 $this->text_domain
    335                             )
    336                         );
    337                     }
    338 
    339                     $error_shown = true;
     317                    $error_text .= '&nbsp;-&nbsp;' . $error . '<br>';
    340318                }
     319                $feedback = '<br><i>Do you see this message but the <b>data already looks good</b>? Just save it once more and this message should be gone!</i>';
     320
     321                $this->show_admin_notice(
     322                    'error',
     323                    __(
     324                        'Not all required settings for the Daisycon WooCommerce pixel plugin have been set',
     325                        $this->text_domain
     326                    ) . ' [<strong>' . $language . '</strong>]<br>' . $error_text . $feedback,
     327                );
    341328            }
    342329        }
     
    455442    {
    456443        $name = sprintf('%s[%s]', $this->option_name, $field_name);
    457         $field_name_old = substr($field_name, 0, -6); // using this makes it backwards compatible (before multi language/site)
    458         $field_value = (isset($this->settings[$field_name]) ? $this->settings[$field_name] : (isset($this->settings[$field_name_old]) ? $this->settings[$field_name_old] : ''));
     444        $field_names = daisycon_name_options($field_name, true);
     445        $field_value = daisycon_get_setting_value($field_names, $this->settings);
    459446
    460447        echo '<input class="regular-text" type="text" id="' . $name . '" name="' . $name . '" value="' . esc_attr($field_value) . '" placeholder="' . $placeholder . '" />';
     
    519506    {
    520507        $group = $args['info']['group'];
    521         $group_old = substr($group, 0, -6); // using this makes it backwards compatible (before multi language/site)
    522         $selected_options = (isset($this->settings[$group]) ? $this->settings[$group] : (isset($this->settings[$group_old]) ? $this->settings[$group_old] : []));
     508        $field_names = daisycon_name_options($group, true);
     509        $selected_options[] = daisycon_get_setting_value($field_names, $this->settings);
    523510
    524511        $all_options = $args['info']['options'];
  • daisycon-woocommerce-pixel/trunk/daisycon-woocommerce.php

    r2779968 r2793902  
    1212 * Plugin URI:        https://www.daisycon.com/nl/tools/woocommerce-conversie-pixel/
    1313 * Description:       This plugin will automatically add the Daisycon Pixel to the WooCommmerce succespage
    14  * Version:           1.6
     14 * Version:           1.6.1
    1515 * Author:            daisycon
    1616 * Author URI:        https://www.daisycon.com
     
    3030 * Currently plugin version.
    3131 */
    32 const DAISYCON_PLUGIN_VERSION = '1.6';
     32const DAISYCON_PLUGIN_VERSION = '1.6.1';
    3333
    3434/**
     
    7979
    8080/**
     81 * Get and set all languages from this website (collect and clean them)
     82 *
     83 * @since  1.6.1
     84 * @return array
     85 */
     86function daisycon_languages()
     87{
     88    $languages = [];
     89
     90    // Add available languages (probably not needed, so since 1.6.1 disabled)
     91    #$languages = get_available_languages() ?? []; // probably not needed, so now removed
     92
     93    // Add current locale
     94    $languages[] = get_locale();
     95
     96    // Add WPML locales if set
     97    $wpmlLanguages = apply_filters('wpml_active_languages', NULL, 'orderby=id&order=desc') ?? [];
     98    if (false === empty($wpmlLanguages))
     99    {
     100        $languages = array_unique(array_merge($languages, array_column($wpmlLanguages, 'default_locale')));
     101    }
     102
     103    return array_unique($languages);
     104}
     105
     106/**
     107 * Get the name options of a field inside the daisycon pixel
     108 * Due different variable names (through updates), all names will be returned here, to provide biggest chance on data!
     109 *
     110 * @param string $name
     111 * @param bool $name_contains_locale
     112 * @param string $locale
     113 *
     114 * @since  1.6.1
     115 * @return mixed
     116 */
     117function daisycon_name_options($name = '', $name_contains_locale = false, $locale = null)
     118{
     119    if (true === empty($name))
     120    {
     121        echo 'The original value is not set';
     122    }
     123
     124    if (false === $name_contains_locale && true === empty($locale))
     125    {
     126        echo 'The name settings are not correct. name_contains_locale or locale should be upddated.';
     127    }
     128
     129    // Strip the locale from the name and collect the locale (to re-attach it later again)
     130    if (true === $name_contains_locale)
     131    {
     132        foreach (daisycon_languages() as $language)
     133        {
     134            if (false === empty(stripos($name, $language)))
     135            {
     136                $name = str_replace('_' . $language,'', $name);
     137                $locale = $language;
     138            }
     139        }
     140    }
     141
     142    return [
     143        $name . '_' . $locale,               // >= v1.6.1
     144        'daisycon_' . $name . '_' . $locale, //  = v1.6
     145        'daisycon_' . $name,                 //  < v1.6
     146        $name,                               //  < v1.6
     147    ];
     148}
     149
     150/**
    81151 * Get a setting value
    82152 *
    83  * @param bool $setting
    84  * @param bool $first
     153 * @param string $setting
     154 * @param array $content
    85155 *
    86156 * @return mixed
    87157 */
    88 function daisycon_get_setting_value($setting = false, $first = false)
     158function daisycon_get_setting_value($setting = '', $content = [])
    89159{
    90     if (empty($setting))
     160    if (true === empty($setting))
    91161    {
    92162        return false;
    93163    }
    94164
    95     $name = $setting . '_' . get_locale();
    96     $name_old = $setting; // using the old name which makes it backwards compatible (before multi language/site)
     165    // When no array is supplied, we'll make it an array with all name options
     166    if (false === is_array($setting))
     167    {
     168        $setting = daisycon_name_options($setting, false, get_locale());
     169    }
    97170
    98     if ($options = get_option('daisycon_woocommerce_options'))
     171    // When there is already content delivered, we don't have to search it again
     172    if (true === empty($content))
    99173    {
    100         if ($first)
     174        $content = get_option('daisycon_woocommerce_options');
     175    }
     176
     177    if (false === empty($content))
     178    {
     179        foreach ($setting as $name)
    101180        {
    102             return $options[isset($options[$name][0]) ? $name : $name_old][0] ?? false;
     181            if (true === isset($content[$name]))
     182            {
     183                return (true === is_array($content[$name]) ? $content[$name][0] : $content[$name]);
     184            }
    103185        }
    104 
    105         return $options[isset($options[$name]) ? $name : $name_old] ?? false;
    106186    }
    107187
  • daisycon-woocommerce-pixel/trunk/public/class-daisycon-woocommerce-public.php

    r2779968 r2793902  
    118118     * @var      array $setting_fields The required setting fields of this plugin.
    119119     */
    120     protected $required_settings = ['campaign_id', 'daisycon_matching_domain', 'daisycon_commission_vat'];
     120    protected $required_settings = ['campaign_id', 'matching_domain', 'lcc_enabled', 'commission_vat'];
    121121
    122122    /**
     
    167167    public function daisycon_lcc_script()
    168168    {
    169         $daisycon_lcc_enabled = daisycon_get_setting_value('daisycon_lcc_enabled', true);
    170         if ('yes' == $daisycon_lcc_enabled)
    171         {
    172             $daisycon_lcc_url_param = daisycon_get_setting_value('daisycon_lcc_url_param');
     169        $lcc_enabled = daisycon_get_setting_value('lcc_enabled');
     170
     171        if ('yes' == $lcc_enabled)
     172        {
     173            $lcc_url_param = daisycon_get_setting_value('lcc_url_param');
    173174            ?>
    174175            <script type="text/javascript">
    175176                (function ($) {
    176177                    const urlParams = new URLSearchParams(window.location.search);
    177                     const networkName = urlParams.get('<?php echo $daisycon_lcc_url_param; ?>');
     178                    const networkName = urlParams.get('<?php echo $lcc_url_param; ?>');
    178179                    if (networkName) {
    179180                        const d = new Date;
     
    205206        }
    206207
    207         // Are all required settings set?
    208208        $settings = $this->get_settings();
    209         $language = get_locale();
    210 
    211         foreach ($this->required_settings as $required_setting)
    212         {
    213             $required_setting = $required_setting . '_' . $language;
    214 
    215             if (
    216                 !isset($settings[$required_setting])
    217                 || (isset($settings[$required_setting])
    218                     && empty($settings[$required_setting]))
    219             )
     209
     210        foreach ($this->required_settings as $setting)
     211        {
     212            if (true === empty(daisycon_get_setting_value($setting, $settings)))
    220213            {
    221214                return false;
     
    223216        }
    224217
    225         $daisycon_lcc_enabled = daisycon_get_setting_value('daisycon_lcc_enabled', true);
    226 
    227         if ('yes' == $daisycon_lcc_enabled && isset($_COOKIE['network']) && $_COOKIE['network'] != 'daisycon')
     218        $lcc_enabled = daisycon_get_setting_value('lcc_enabled', $settings);
     219
     220        if ('yes' === $lcc_enabled && isset($_COOKIE['network']) && 'daisycon' !== $_COOKIE['network'])
    228221        {
    229222            // If LCC is enabled, but the from network is SET and NOT `daisycon`.
     
    242235    protected function _get_daisycon_pixel_url()
    243236    {
    244         if ($matching_domain_setting = daisycon_get_setting_value('daisycon_matching_domain'))
    245         {
    246             if (!isset($matching_domain_setting[0]))
    247             {
    248                 return false;
    249             }
     237        $matching_domain = daisycon_get_setting_value('matching_domain');
     238        if (false === $matching_domain)
     239        {
     240            return false;
    250241        }
    251242
     
    255246        return apply_filters(
    256247            'daisycon_woocommerce_pixel_url',
    257             sprintf($url_string, $matching_domain_setting[0], $variables)
     248            sprintf($url_string, $matching_domain, $variables)
    258249        );
    259250    }
     
    283274            'z'   => $this->order->get_billing_postcode(),
    284275            'cur' => $this->order->get_currency(),
    285             'src' => $this->source_name . '-' . $this->version,
     276            'src' => 'dc-' . $this->source_name . '-' . $this->version,
    286277        ];
    287278
    288         $daisycon_lcc_enabled = daisycon_get_setting_value('daisycon_lcc_enabled', true);
    289         if ($daisycon_lcc_enabled == 'yes' && !isset($_COOKIE['network']))
     279        $lcc_enabled = daisycon_get_setting_value('lcc_enabled');
     280        if ('yes' === $lcc_enabled && !isset($_COOKIE['network']))
    290281        {
    291282            // If LCC is enabled, but the from network is NOT SET (catch all).
     
    476467        if (is_null($this->excl_tax))
    477468        {
    478             $price_excl_tax = daisycon_get_setting_value('daisycon_commission_vat');
    479             $this->excl_tax = (isset($price_excl_tax[0]) && $price_excl_tax[0] === 'excl');
     469            $price_excl_tax = daisycon_get_setting_value('commission_vat');
     470            $this->excl_tax = (isset($price_excl_tax) && $price_excl_tax === 'excl');
    480471        }
    481472
Note: See TracChangeset for help on using the changeset viewer.