Changeset 2793902
- Timestamp:
- 10/04/2022 08:32:15 AM (4 years ago)
- Location:
- daisycon-woocommerce-pixel/trunk
- Files:
-
- 1 deleted
- 5 edited
-
README.txt (modified) (1 diff)
-
admin/assets/daisycon-woocommerce-admin.js (modified) (2 diffs)
-
admin/class-daisycon-woocommerce-settings.php (modified) (11 diffs)
-
admin/js (deleted)
-
daisycon-woocommerce.php (modified) (3 diffs)
-
public/class-daisycon-woocommerce-public.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
daisycon-woocommerce-pixel/trunk/README.txt
r2779968 r2793902 57 57 58 58 == Changelog == 59 60 = 1.6.1 = 61 * Updated configuration regarding languages and names 59 62 60 63 = 1.6 = -
daisycon-woocommerce-pixel/trunk/admin/assets/daisycon-woocommerce-admin.js
r2779968 r2793902 3 3 4 4 $(document).ready(function(){ 5 let current_value = 'yes'; 6 let td = null; 7 8 // Old code, can probably be removed 5 9 $('body').on('click', '#the-list .editinline', function(){ 6 10 var parent_tr = $(this).closest('tr'), … … 14 18 $daisycon_input.val($daisycon_inline_data.text()); 15 19 }); 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 16 50 }); 17 51 -
daisycon-woocommerce-pixel/trunk/admin/class-daisycon-woocommerce-settings.php
r2779968 r2793902 73 73 * @var array $setting_fields The required setting fields of this plugin. 74 74 */ 75 protected $required_settings = ['campaign_id', ' daisycon_matching_domain', 'daisycon_commission_vat'];75 protected $required_settings = ['campaign_id', 'matching_domain', 'lcc_enabled', 'commission_vat']; 76 76 77 77 /** … … 146 146 } 147 147 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); 149 149 } 150 150 … … 156 156 protected function _get_setting_fields() 157 157 { 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(); 165 159 166 160 if (is_null($this->setting_fields)) … … 197 191 ], 198 192 'campaign_id_' . $language => [ 199 'title' => __('Campaign ID (required)', $this->text_domain),193 'title' => __('Campaign ID', $this->text_domain), 200 194 'type' => 'text', 201 195 'placeholder' => '', … … 204 198 'title' => __('Matching Domain', $this->text_domain), 205 199 'type' => 'select', 206 'group' => ' daisycon_matching_domain_' . $language,200 'group' => 'matching_domain_' . $language, 207 201 'options' => [ 202 '' => __('Select', $this->text_domain), 208 203 'at19.net' => __('at19.net', $this->text_domain), 209 204 'bdt9.net' => __('bdt9.net', $this->text_domain), … … 222 217 ], 223 218 ], 224 ' daisycon_lcc_enabled_' . $language=> [219 'lcc_enabled_' . $language => [ 225 220 'title' => __('Use LCC cookie', $this->text_domain), 226 221 'type' => 'select', 227 'group' => ' daisycon_lcc_enabled_' . $language,222 'group' => 'lcc_enabled_' . $language, 228 223 'options' => [ 224 '' => __('Select', $this->text_domain), 229 225 'no' => __('No', $this->text_domain), 230 226 'yes' => __('Yes', $this->text_domain), 231 227 ], 232 228 ], 233 ' daisycon_lcc_url_param_' . $language=> [229 'lcc_url_param_' . $language => [ 234 230 'title' => __( 235 'LCC `network` url parameter (?the_configured_parameter_below=daisycon)',231 'LCC network', 236 232 $this->text_domain 237 233 ), … … 242 238 'title' => __('Commission VAT', $this->text_domain), 243 239 'type' => 'select', 244 'group' => ' daisycon_commission_vat_' . $language,240 'group' => 'commission_vat_' . $language, 245 241 'options' => [ 242 '' => __('Select', $this->text_domain), 246 243 'incl' => __('Including VAT', $this->text_domain), 247 244 'excl' => __('Excluding VAT', $this->text_domain), … … 290 287 { 291 288 $settings = $this->get_settings(); 292 $error_shown = false;293 289 294 290 if (wp_doing_ajax()) … … 297 293 } 298 294 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 304 300 foreach ($this->required_settings as $required_setting) 305 301 { 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))) 307 306 { 308 continue; 307 // Current setting not found, so error the "nice" name of the field that is missing 308 $errors[$language][] = $feedbackNames[$name]['title']; 309 309 } 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) 315 316 { 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 .= ' - ' . $error . '<br>'; 340 318 } 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 ); 341 328 } 342 329 } … … 455 442 { 456 443 $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); 459 446 460 447 echo '<input class="regular-text" type="text" id="' . $name . '" name="' . $name . '" value="' . esc_attr($field_value) . '" placeholder="' . $placeholder . '" />'; … … 519 506 { 520 507 $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); 523 510 524 511 $all_options = $args['info']['options']; -
daisycon-woocommerce-pixel/trunk/daisycon-woocommerce.php
r2779968 r2793902 12 12 * Plugin URI: https://www.daisycon.com/nl/tools/woocommerce-conversie-pixel/ 13 13 * Description: This plugin will automatically add the Daisycon Pixel to the WooCommmerce succespage 14 * Version: 1.6 14 * Version: 1.6.1 15 15 * Author: daisycon 16 16 * Author URI: https://www.daisycon.com … … 30 30 * Currently plugin version. 31 31 */ 32 const DAISYCON_PLUGIN_VERSION = '1.6 ';32 const DAISYCON_PLUGIN_VERSION = '1.6.1'; 33 33 34 34 /** … … 79 79 80 80 /** 81 * Get and set all languages from this website (collect and clean them) 82 * 83 * @since 1.6.1 84 * @return array 85 */ 86 function 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 */ 117 function 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 /** 81 151 * Get a setting value 82 152 * 83 * @param bool$setting84 * @param bool $first153 * @param string $setting 154 * @param array $content 85 155 * 86 156 * @return mixed 87 157 */ 88 function daisycon_get_setting_value($setting = false, $first = false)158 function daisycon_get_setting_value($setting = '', $content = []) 89 159 { 90 if ( empty($setting))160 if (true === empty($setting)) 91 161 { 92 162 return false; 93 163 } 94 164 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 } 97 170 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)) 99 173 { 100 if ($first) 174 $content = get_option('daisycon_woocommerce_options'); 175 } 176 177 if (false === empty($content)) 178 { 179 foreach ($setting as $name) 101 180 { 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 } 103 185 } 104 105 return $options[isset($options[$name]) ? $name : $name_old] ?? false;106 186 } 107 187 -
daisycon-woocommerce-pixel/trunk/public/class-daisycon-woocommerce-public.php
r2779968 r2793902 118 118 * @var array $setting_fields The required setting fields of this plugin. 119 119 */ 120 protected $required_settings = ['campaign_id', ' daisycon_matching_domain', 'daisycon_commission_vat'];120 protected $required_settings = ['campaign_id', 'matching_domain', 'lcc_enabled', 'commission_vat']; 121 121 122 122 /** … … 167 167 public function daisycon_lcc_script() 168 168 { 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'); 173 174 ?> 174 175 <script type="text/javascript"> 175 176 (function ($) { 176 177 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; ?>'); 178 179 if (networkName) { 179 180 const d = new Date; … … 205 206 } 206 207 207 // Are all required settings set?208 208 $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))) 220 213 { 221 214 return false; … … 223 216 } 224 217 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']) 228 221 { 229 222 // If LCC is enabled, but the from network is SET and NOT `daisycon`. … … 242 235 protected function _get_daisycon_pixel_url() 243 236 { 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; 250 241 } 251 242 … … 255 246 return apply_filters( 256 247 'daisycon_woocommerce_pixel_url', 257 sprintf($url_string, $matching_domain _setting[0], $variables)248 sprintf($url_string, $matching_domain, $variables) 258 249 ); 259 250 } … … 283 274 'z' => $this->order->get_billing_postcode(), 284 275 'cur' => $this->order->get_currency(), 285 'src' => $this->source_name . '-' . $this->version,276 'src' => 'dc-' . $this->source_name . '-' . $this->version, 286 277 ]; 287 278 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'])) 290 281 { 291 282 // If LCC is enabled, but the from network is NOT SET (catch all). … … 476 467 if (is_null($this->excl_tax)) 477 468 { 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'); 480 471 } 481 472
Note: See TracChangeset
for help on using the changeset viewer.