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)) {