Body class filter implemented. has-alert and has-alert-{id}

This commit is contained in:
dcooperdalrymple
2022-04-13 09:48:14 -05:00
parent 60e924ba32
commit b3ea11c7ce

View File

@@ -33,6 +33,8 @@ class Display {
add_action('display_alerts', array(__CLASS__, 'display_alerts')); add_action('display_alerts', array(__CLASS__, 'display_alerts'));
break; break;
} }
add_filter('body_class', [__CLASS__, 'body_class'], 10, 1);
} }
static function enqueue_scripts() { static function enqueue_scripts() {
@@ -56,6 +58,17 @@ class Display {
self::load_template('loop-end'); 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()) { private static function load_template($filename, $filepart = '', $echo = true, $vars = array()) {
$path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '-' . $filepart . '.php'; $path = \OgreAlert\Settings::get('path') . 'templates/' . $filename . '-' . $filepart . '.php';
if (!file_exists($path)) { if (!file_exists($path)) {