Gocodebox_Banner_Notifier::get_next_notification()
Get the highest priority applicable notification from the list.
Contents
Source Source
File: libraries/banner-notifications/src/notifications.php
function get_next_notification() {
global $current_user;
if ( empty( $current_user->ID ) ) {
return false;
}
// If debugging, clear the transient and get a specific notification.
if ( ! empty( $_REQUEST[ "{$this->prefix}_notification" ] ) ) {
delete_transient( "{$this->prefix}_notifications_{$this->version}" );
$notifications = $this->get_all_notifications();
if ( ! empty( $notifications ) ) {
foreach ( $notifications as $notification ) {
if ( $notification->id == $_REQUEST[ "{$this->prefix}_notification" ] ) {
return $notification;
}
}
return false;
} else {
return false;
}
}
// Get all applicable notifications.
$notifications = $this->get_all_notifications();
if ( empty( $notifications ) ) {
return false;
}
// Filter out archived notifications.
$filtered_notifications = array();
$archived_notifications = get_user_meta( $current_user->ID, "{$this->prefix}_archived_notifications", true );
foreach ( $notifications as $notification ) {
if ( ( is_array( $archived_notifications ) && array_key_exists( $notification->id, $archived_notifications ) ) ) {
continue;
}
$filtered_notifications[] = $notification;
}
// Return the first one.
if ( ! empty( $filtered_notifications ) ) {
$next_notification = $filtered_notifications[0];
} else {
$next_notification = false;
}
return $next_notification;
}
Expand full source code Collapse full source code View on GitHub