HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux vm8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: afleverb (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //var/www/wintergenomics_site/wp-content/plugins/wordpress-seo/src/helpers/notification-helper.php
<?php

namespace Yoast\WP\SEO\Helpers;

use Yoast_Notification;
use Yoast_Notification_Center;

/**
 * A helper object for notifications.
 */
class Notification_Helper {

	/**
	 * Restores a notification (wrapper function).
	 *
	 * @codeCoverageIgnore
	 *
	 * @param Yoast_Notification $notification The notification to restore.
	 *
	 * @return bool True if restored, false otherwise.
	 */
	public function restore_notification( Yoast_Notification $notification ) {
		return Yoast_Notification_Center::restore_notification( $notification );
	}

	/**
	 * Return the notifications sorted on type and priority. (wrapper function)
	 *
	 * @codeCoverageIgnore
	 *
	 * @return array|Yoast_Notification[] Sorted Notifications
	 */
	public function get_sorted_notifications() {
		$notification_center = Yoast_Notification_Center::get();

		return $notification_center->get_sorted_notifications();
	}

	/**
	 * Check if the user has dismissed a notification. (wrapper function)
	 *
	 * @param Yoast_Notification $notification The notification to check for dismissal.
	 * @param int|null           $user_id      User ID to check on.
	 *
	 * @codeCoverageIgnore
	 *
	 * @return bool
	 */
	private function is_notification_dismissed( Yoast_Notification $notification, $user_id = null ) {
		return Yoast_Notification_Center::is_notification_dismissed( $notification, $user_id );
	}

	/**
	 * Parses all the notifications to an array with just warnings notifications, and splitting them between dismissed
	 * and active.
	 *
	 * @return array<Yoast_Notification>
	 */
	public function get_notifications(): array {
		$all_notifications       = $this->get_sorted_notifications();
		$notifications           = \array_filter(
			$all_notifications,
			static function ( $notification ) {
				return $notification->get_type() !== 'error';
			}
		);
		$dismissed_notifications = \array_filter(
			$notifications,
			function ( $notification ) {
				return $this->is_notification_dismissed( $notification );
			}
		);
		$active_notifications    = \array_diff( $notifications, $dismissed_notifications );

		return [
			'dismissed' => \array_map(
				static function ( $notification ) {
					return $notification->to_array();
				},
				$dismissed_notifications
			),
			'active'    => \array_map(
				static function ( $notification ) {
					return $notification->to_array();
				},
				$active_notifications
			),
		];
	}

	/**
	 * Parses all the notifications to an array with just error notifications, and splitting them between dismissed and
	 * active.
	 *
	 * @return array<Yoast_Notification>
	 */
	public function get_problems(): array {
		$all_notifications  = $this->get_sorted_notifications();
		$problems           = \array_filter(
			$all_notifications,
			static function ( $notification ) {
				return $notification->get_type() === 'error';
			}
		);
		$dismissed_problems = \array_filter(
			$problems,
			function ( $notification ) {
				return $this->is_notification_dismissed( $notification );
			}
		);
		$active_problems    = \array_diff( $problems, $dismissed_problems );

		return [
			'dismissed' => \array_map(
				static function ( $notification ) {
					return $notification->to_array();
				},
				$dismissed_problems
			),
			'active'    => \array_map(
				static function ( $notification ) {
					return $notification->to_array();
				},
				$active_problems
			),
		];
	}
}