Skip to content

Commit

Permalink
Adds check for empty cookie value
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Walter committed Sep 30, 2020
1 parent 1bbfe95 commit 2688632
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Add `?utm_catcher_params` to any link `href` URL and the plugin will replace it

## Changelog

### 1.1.1
* Adds check for empty cookie before setting PHP cookie. Could cause caching issues with nginx/Varnish.

### 1.1.0
* Adds support for `utm_catcher_params` token replacement in link URLs.
* Adds minified version of plugin's JavaScript.
Expand Down
17 changes: 9 additions & 8 deletions vital-utm-catcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Vital UTM Catcher
Plugin URI: https://vtldesign.com
Description: Simple UTM parameter processor
Version: 1.1.0
Version: 1.1.1
Author: Vital
Author URI: https://vtldesign.com
Text Domain: vital
Expand Down Expand Up @@ -85,7 +85,7 @@ class Vital_Utm_Catcher {
* @return void
*/
public function __construct() {
$this->_version = '1.1.0';
$this->_version = '1.1.1';
$this->assets_dir = plugin_dir_path(__FILE__);
$this->assets_url = plugin_dir_url(__FILE__);
$this->suffix = (defined('SCRIPT_DEBUG') && SCRIPT_DEBUG) ? '' : '.min';
Expand Down Expand Up @@ -117,11 +117,11 @@ public function catch() {

foreach ($this->utm_params as $field) {
if (isset($_GET[$field]) && $_GET[$field] !== '') {
$cookie_name = htmlspecialchars($_GET[$field], ENT_QUOTES, 'UTF-8');
$cookie_value = htmlspecialchars($_GET[$field], ENT_QUOTES, 'UTF-8');
} elseif (isset($_COOKIE[$field]) && $_COOKIE[$field] !== '') {
$cookie_name = $_COOKIE[$field];
$cookie_value = $_COOKIE[$field];
} else {
$cookie_name = '';
$cookie_value = '';
}

$domain = parse_url(get_site_url(), PHP_URL_HOST);
Expand All @@ -142,9 +142,10 @@ public function catch() {
$domain = substr($domain, 0, $port);
}

setcookie($field, $cookie_name, strtotime("+{$this->cookie_expires} seconds"), $domain);

$_COOKIE[$field] = $cookie_name;
if ($cookie_value !== '') {
setcookie($field, $cookie_value, strtotime("+{$this->cookie_expires} seconds"), $domain);
$_COOKIE[$field] = $cookie_value;
}
}
}

Expand Down

0 comments on commit 2688632

Please sign in to comment.