From b3ea11c7cee8d9ef5edf6f1d620f6f9ca28fc20d Mon Sep 17 00:00:00 2001 From: dcooperdalrymple Date: Wed, 13 Apr 2022 09:48:14 -0500 Subject: [PATCH] Body class filter implemented. `has-alert` and `has-alert-{id}` --- inc/display.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/inc/display.php b/inc/display.php index afbe537..ae5b81c 100644 --- a/inc/display.php +++ b/inc/display.php @@ -33,6 +33,8 @@ class Display { add_action('display_alerts', array(__CLASS__, 'display_alerts')); break; } + + add_filter('body_class', [__CLASS__, 'body_class'], 10, 1); } static function enqueue_scripts() { @@ -56,6 +58,17 @@ class Display { self::load_template('loop-end'); } + static function body_class($classes) { + if (is_admin() || !\OgreAlert\Alert::has_active()) return $classes; + + $classes[] = 'has-alert'; + foreach (\OgreAlert\Alert::get_active() as $id) { + $classes[] = sprintf('has-alert-%d', $id); + } + + return $classes; + } + private static function load_template($filename, $filepart = '', $echo = true, $vars = array()) { $path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '-' . $filepart . '.php'; if (!file_exists($path)) {