Gocodebox_Banner_Notifier::get_all_notifications()

Get notifications from the notification server.


Source Source

File: libraries/banner-notifications/src/notifications.php

	function get_all_notifications() {
		$notifications = get_transient( "{$this->prefix}_notifications_{$this->version}" );

		if ( empty( $notifications ) ) {
			// Set to NULL in case the below times out or fails, this way we only check once a day.
			set_transient( "{$this->prefix}_notifications_{$this->version}", 'NULL', 86400 );

			// We use the filter to hit our testing servers.
			$notification_url = apply_filters( "{$this->prefix}_notifications_url", esc_url( $this->notifications_url ) );

			// Get notifications.
			$remote_notifications = wp_remote_get( $notification_url );
			$notifications        = json_decode( wp_remote_retrieve_body( $remote_notifications ) );

			// Update transient if we got something.
			if ( ! empty( $notifications ) ) {
				set_transient( "{$this->prefix}_notifications_{$this->version}", $notifications, 86400 );
			}
		}

		if ( ! is_array( $notifications ) ) {
			$notifications = array();
		}

		// Filter notifications by start/end date.
		$active_notifications = array();
		foreach ( $notifications as $notification ) {
			$active_notifications[] = $notification;
		}

		// Filter out notifications based on show/hide rules.
		$applicable_notifications = array();
		foreach ( $active_notifications as $notification ) {
			if ( $this->is_notification_applicable( $notification ) ) {
				$applicable_notifications[] = $notification;
			}
		}

		// Sort by priority.
		$applicable_notifications = wp_list_sort( $applicable_notifications, 'priority' );

		return $applicable_notifications;
	}


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.