diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4a9ccc8..9fdff35 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
+## [1.5.5] - 2024-12-12
+
+### Changed
+
+- Check variable before trim to prevent PHP warning
+
## [1.5.4] - 2024-11-28
### Added
diff --git a/index.php b/index.php
index a50a078..16746e3 100644
--- a/index.php
+++ b/index.php
@@ -12,7 +12,7 @@
* Plugin URI: https://github.com/dxw/analytics-with-consent
* Description: Google Analytics + CIVIC Cookie Control
* Author: dxw
- * Version: 1.5.4
+ * Version: 1.5.5
* Network: True
*/
diff --git a/src/Scripts.php b/src/Scripts.php
index 0526a48..93e4214 100644
--- a/src/Scripts.php
+++ b/src/Scripts.php
@@ -22,12 +22,12 @@ public function addActionLinks(array $links): array
public function enqueueScripts(): void
{
- $apiKey = trim(get_field('civic_cookie_control_api_key', 'option'));
- $productType = trim(get_field('civic_cookie_control_product_type', 'option'));
- $googleAnalyticsId = trim(get_field('google_analytics_id', 'option'));
- $ga4Id = trim(get_field('ga_4_id', 'option'));
- $gtmId = trim(get_field('google_analytics_gtm', 'option'));
- $hotjarId = trim(get_field('hotjar_id', 'option'));
+ $apiKey = trim(get_field('civic_cookie_control_api_key', 'option') ?? '');
+ $productType = trim(get_field('civic_cookie_control_product_type', 'option') ?? '');
+ $googleAnalyticsId = trim(get_field('google_analytics_id', 'option') ?? '');
+ $ga4Id = trim(get_field('ga_4_id', 'option') ?? '');
+ $gtmId = trim(get_field('google_analytics_gtm', 'option') ?? '');
+ $hotjarId = trim(get_field('hotjar_id', 'option') ?? '');
if ($apiKey && $productType) {
wp_enqueue_script('civicCookieControl', 'https://cc.cdn.civiccomputing.com/9/cookieControl-9.x.min.js');
wp_enqueue_script('civicCookieControlDefaultAnalytics', plugins_url('/assets/js/analytics.js', dirname(__FILE__)), ['civicCookieControl']);
@@ -49,9 +49,9 @@ public function enqueueStyles(): void
public function addGA4(): void
{
- $apiKey = trim(get_field('civic_cookie_control_api_key', 'option'));
- $productType = trim(get_field('civic_cookie_control_product_type', 'option'));
- $ga4Id = trim(get_field('ga_4_id', 'option'));
+ $apiKey = trim(get_field('civic_cookie_control_api_key', 'option') ?? '');
+ $productType = trim(get_field('civic_cookie_control_product_type', 'option') ?? '');
+ $ga4Id = trim(get_field('ga_4_id', 'option') ?? '');
if ($apiKey && $productType && $ga4Id) {
printf('', esc_attr($ga4Id));
}
@@ -59,9 +59,9 @@ public function addGA4(): void
public function addGTM(): void
{
- $apiKey = trim(get_field('civic_cookie_control_api_key', 'option'));
- $productType = trim(get_field('civic_cookie_control_product_type', 'option'));
- $gtmId = trim(get_field('google_analytics_gtm', 'option'));
+ $apiKey = trim(get_field('civic_cookie_control_api_key', 'option') ?? '');
+ $productType = trim(get_field('civic_cookie_control_product_type', 'option') ?? '');
+ $gtmId = trim(get_field('google_analytics_gtm', 'option') ?? '');
if ($apiKey && $productType && $gtmId) {
printf("", esc_js($gtmId));
}
@@ -90,8 +90,8 @@ private function defaultConfig(): array
];
}
return apply_filters('awc_civic_cookie_control_config', [
- 'apiKey' => trim(get_field('civic_cookie_control_api_key', 'option')),
- 'product' => trim(get_field('civic_cookie_control_product_type', 'option')),
+ 'apiKey' => trim(get_field('civic_cookie_control_api_key', 'option') ?? ''),
+ 'product' => trim(get_field('civic_cookie_control_product_type', 'option') ?? ''),
'closeStyle' => 'button',
'initialState' => 'open',
'text' => [