From dd0b2cc17b637f027c7a47aaa396ed839d637fc2 Mon Sep 17 00:00:00 2001 From: Laura Birek Date: Wed, 18 Sep 2024 14:40:41 -0700 Subject: [PATCH] ability to hide alerts on specific pages --- inc/acf-json/group_653fde8f6b970.json | 36 +++++++++++++++++++++++++++ inc/lib/init.php | 28 ++++++++++++++------- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/inc/acf-json/group_653fde8f6b970.json b/inc/acf-json/group_653fde8f6b970.json index 36cecc1..6d0f963 100644 --- a/inc/acf-json/group_653fde8f6b970.json +++ b/inc/acf-json/group_653fde8f6b970.json @@ -118,6 +118,42 @@ "media_upload": 0, "delay": 0, "parent_repeater": "field_653fde8fdf14f" + }, + { + "key": "field_6696d6a25a6c1", + "label": "Hide Alert on Specific Pages", + "name": "", + "aria-label": "", + "type": "relationship", + "instructions": "", + "required": 0, + "conditional_logic": 0, + "wrapper": { + "width": "", + "class": "", + "id": "" + }, + "post_type": [ + "post", + "page" + ], + "post_status": [ + "publish", + "future" + ], + "taxonomy": "", + "filters": [ + "search", + "post_type", + "taxonomy" + ], + "return_format": "id", + "min": "", + "max": "", + "elements": "", + "bidirectional": 0, + "bidirectional_target": [], + "parent_repeater": "field_653fde8fdf14f" } ] } diff --git a/inc/lib/init.php b/inc/lib/init.php index c4d0ede..ffeb8ba 100644 --- a/inc/lib/init.php +++ b/inc/lib/init.php @@ -216,17 +216,27 @@ function alerts($position) foreach ($alerts as $alert) { if ($alert['enabled']) { - $alert_position = strtolower($alert['position']); - - if ($alert['message'] && !isset($_COOKIE['tofino-alert-' . $i . '-closed']) && $position === $alert_position) { - \Tofino\Helpers\hm_get_template_part('templates/partials/alert', [ - 'position' => $alert_position, - 'message' => $alert['message'], - 'id' => $i - ]); + // now check if alerts are hidden on specific pages + + if (is_array($alert['hide_alert_on_specific_pages'])) { + $excludepages = $alert['hide_alert_on_specific_pages']; + } else { + $excludepages = array(); } - } + if (!in_array(get_the_ID(), $excludepages)) { + $alert_position = strtolower($alert['position']); + if ($alert['message'] && !isset($_COOKIE['tofino-alert-' . $i . '-closed']) && $position === $alert_position) { + \Tofino\Helpers\hm_get_template_part('templates/partials/alert', [ + 'position' => $alert_position, + 'message' => $alert['message'], + 'id' => $i + ]); + } + } else { + // alert excluded from current page + } + } $i++; } }