has_active function with ogrealert/has_active filter.

This commit is contained in:
dcooperdalrymple
2022-04-13 09:47:35 -05:00
parent bb08ce8a51
commit 60e924ba32
2 changed files with 6 additions and 4 deletions

View File

@@ -140,6 +140,9 @@ class Alert {
return apply_filters('ogrealert/get_active', $alerts); return apply_filters('ogrealert/get_active', $alerts);
} }
public static function has_active() {
return apply_filters('ogrealert/has_active', !empty(self::get_active()));
}
public static function get_random() { public static function get_random() {
$alerts = self::get_active(); $alerts = self::get_active();

View File

@@ -18,7 +18,7 @@ class Display {
} }
static function init() { static function init() {
if (empty(\OgreAlert\Alert::get_active())) return; if (!\OgreAlert\Alert::has_active()) return;
add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts')); add_action('wp_enqueue_scripts', array(__CLASS__, 'enqueue_scripts'));
@@ -47,11 +47,10 @@ class Display {
} }
static function display_alerts() { static function display_alerts() {
$ids = \OgreAlert\Alert::get_active(); if (!\OgreAlert\Alert::has_active()) return;
if (empty($ids)) return;
self::load_template('loop-start'); self::load_template('loop-start');
foreach ($ids as $id) { foreach (\OgreAlert\Alert::get_active() as $id) {
self::load_template('alert', \OgreAlert\Priority::get($id), true, array('id' => $id)); self::load_template('alert', \OgreAlert\Priority::get($id), true, array('id' => $id));
} }
self::load_template('loop-end'); self::load_template('loop-end');