Yoast_Notification_Center::add_notification()publicYoast 1.0

Add notification to the cookie.

Метод класса: Yoast_Notification_Center{}

Хуков нет.

Возвращает

null. Ничего (null).

Использование

$Yoast_Notification_Center = new Yoast_Notification_Center();
$Yoast_Notification_Center->add_notification( $notification );
$notification(Yoast_Notification) (обязательный)
Notification object instance.

Код Yoast_Notification_Center::add_notification() Yoast 21.6

public function add_notification( Yoast_Notification $notification ) {

	$callback = [ $this, __FUNCTION__ ];
	$args     = func_get_args();
	if ( $this->queue_transaction( $callback, $args ) ) {
		return;
	}

	// Don't add if the user can't see it.
	if ( ! $notification->display_for_current_user() ) {
		return;
	}

	$notification_id = $notification->get_id();
	$user_id         = $notification->get_user_id();

	// Empty notifications are always added.
	if ( $notification_id !== '' ) {

		// If notification ID exists in notifications, don't add again.
		$present_notification = $this->get_notification_by_id( $notification_id, $user_id );
		if ( ! is_null( $present_notification ) ) {
			$this->remove_notification( $present_notification, false );
		}

		if ( is_null( $present_notification ) ) {
			$this->new[] = $notification_id;
		}
	}

	// Add to list.
	$this->notifications[ $user_id ][] = $notification;

	$this->notifications_need_storage = true;
}