Body class filter implemented. has-alert and has-alert-{id}
This commit is contained in:
@@ -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)) {
|
||||
|
||||
Reference in New Issue
Block a user