Skip to content

Commit eac3f0a

Browse files
authored
Merge pull request #12 from tawk/fix/display-widget-show-pages
fix undefined variable `$showPages`
2 parents 442a328 + f1bbe57 commit eac3f0a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tawk_to/src/core/TawktoGenerator.php

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ private function shouldDisplayWidget($options = null)
9292
// prepare visibility
9393
$currentUrl = $base_url.$_SERVER["REQUEST_URI"];
9494
if ($options->always_display == false) {
95-
if (UrlPatternMatcher::match($currentUrl, $showPages)) {
95+
$show_pages = json_decode($options->show_oncustom);
96+
97+
if (UrlPatternMatcher::match($currentUrl, $show_pages)) {
9698
$show = true;
9799
}
98100

@@ -595,12 +597,18 @@ public function setOptions($options)
595597
switch ($column) {
596598
case 'hide_oncustom':
597599
case 'show_oncustom':
598-
// replace newlines and returns with comma, and convert to array for saving
600+
// split by newlines, then remove empty lines
599601
$value = urldecode($value);
600-
$value = str_ireplace(["\r\n", "\r", "\n"], ',', $value);
601-
$value = explode(",", $value);
602-
$value = (empty($value) || !$value) ? array() : $value;
603-
$jsonOpts[$column] = json_encode($value);
602+
$value = str_ireplace("\r", "\n", $value);
603+
$value = explode("\n", $value);
604+
$non_empty_values = array();
605+
foreach ($value as $str) {
606+
$trimmed = trim($str);
607+
if ($trimmed !== '') {
608+
$non_empty_values[] = $trimmed;
609+
}
610+
}
611+
$jsonOpts[$column] = json_encode($non_empty_values);
604612
break;
605613

606614
case 'show_onfrontpage':

0 commit comments

Comments
 (0)