Gocodebox_Banner_Notifier::notifications_pause()
Have we shown too many notifications recently.
Description Description
By default we limit to 1 notification per 12 hour period and 3 notifications per week.
Source Source
File: libraries/banner-notifications/src/notifications.php
function notifications_pause() {
global $current_user;
// No user? Pause.
if ( empty( $current_user ) ) {
return true;
}
$archived_notifications = get_user_meta( $current_user->ID, "{$this->prefix}_archived_notifications", true );
if ( ! is_array( $archived_notifications ) ) {
// If the user has not yet archived a notification, assume that this is a new install or that they are a new admin.
// Either way, we want to delay their first notification.
// We can do this by creating a "delay" archived notification with an archive day 7 days in the future.
update_user_meta( $current_user->ID, "{$this->prefix}_archived_notifications", array( 'initial_notification_delay' => date_i18n( 'c', strtotime( '+7 days' ) ) ) );
return true;
}
$archived_notifications = array_values( $archived_notifications );
$num = count( $archived_notifications );
// TODO: Switch as current_time( 'timestamp' ) is deprecated.
$now = current_time( 'timestamp' );
// No archived (dismissed) notifications? Don't pause.
if ( empty( $archived_notifications ) ) {
return false;
}
// Last notification was dismissed < 12 hours ago. Pause.
$last_notification_date = $archived_notifications[ $num - 1 ];
if ( strtotime( $last_notification_date, $now ) > ( $now - 3600 * 12 ) ) {
return true;
}
// If we have < 3 archived notifications. Don't pause.
if ( $num < 3 ) {
return false;
}
// If we've shown 3 this week already. Pause.
$third_last_notification_date = $archived_notifications[ $num - 3 ];
if ( strtotime( $third_last_notification_date, $now ) > ( $now - 3600 * 24 * 7 ) ) {
return true;
}
// If we've gotten here, don't pause.
return false;
}
Expand full source code Collapse full source code View on GitHub