Automator_Notifications::verify( array $notifications )

Verify notification data before it is saved.


Parameters Parameters

$notifications

(Required) Array of notifications items to verify.


Top ↑

Return Return

(array)


Source Source

File: src/core/admin/notifications/notifications.php

	public function verify( $notifications ) { // phpcs:ignore Generic.Metrics.CyclomaticComplexity.TooHigh
		$data = array();
		if ( ! is_array( $notifications ) || empty( $notifications ) ) {
			return $data;
		}
		$option = $this->get_option();
		foreach ( $notifications as $notification ) {
			// The message and license should never be empty, if they are, ignore.
			if ( empty( $notification['content'] ) || empty( $notification['type'] ) ) {
				continue;
			}
			// Ignore if license type does not match.
			$license_type = $this->get_license_type();
			if ( ! in_array( $license_type, $notification['type'], true ) ) {
				continue;
			}
			// Ignore if notification is not ready to display(based on start time).
			if ( ! empty( $notification['start'] ) && time() < strtotime( $notification['start'] ) ) {
				continue;
			}
			// Ignore if expired.
			if ( ! empty( $notification['end'] ) && time() > strtotime( $notification['end'] ) ) {
				continue;
			}
			// Ignore if notification has already been dismissed.
			$notification_already_dismissed = false;
			if ( is_array( $option['dismissed'] ) && ! empty( $option['dismissed'] ) ) {
				foreach ( $option['dismissed'] as $dismiss_notification ) {
					if ( $notification['id'] === $dismiss_notification['id'] ) {
						$notification_already_dismissed = true;
						break;
					}
				}
			}
			if ( true === $notification_already_dismissed ) {
				continue;
			}
			// Ignore if notification existed before installing automator.
			// Prevents bombarding the user with notifications after activation.
			$over_time = get_option( 'automator_over_time', array() );
			if (
				! empty( $over_time['installed_date'] ) &&
				! empty( $notification['start'] ) &&
				$over_time['installed_date'] > strtotime( $notification['start'] )
			) {
				continue;
			}
			$data[] = $notification;
		}
		return $data;
	}


Top ↑

Changelog Changelog

Changelog
VersionDescription
{VERSION}Introduced.