HEX
Server: Apache/2.4.65 (Debian)
System: Linux 88f31f35b0b8 6.1.0-38-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.147-1 (2025-08-02) x86_64
User: www-data (33)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: /var/www/html/wp-content/plugins/wp-asset-clean-up/classes/PluginNotifications.php
<?php
/** @noinspection MultipleReturnStatementsInspection */

namespace WpAssetCleanUp;

/**
 * Class PluginNotifications
 * @package WpAssetCleanUp
 */
class PluginNotifications
{
	/**
	 *
	 */
	const JSON_URL = '';

	/**
	 * PluginNotifications constructor.
	 */
	public function __construct()
	{

	}

	/**
	 * @return array|\WP_Error
	 */
	public function getJsonData()
	{
		$response = wp_remote_get( self::JSON_URL );

		if ( is_wp_error( $response ) ) {
			return $response;
		}

		$body = wp_remote_retrieve_body( $response );

		if ( empty( $body ) ) {
			return array();
		}

		return $this->validateJsonData( json_decode( $body, true ) );
	}

	/**
	 * @param $entries
	 *
	 * @return array
	 */
	public function validateJsonData($entries)
	{
		$filteredEntries = array();

		if ( empty( $entries ) || ! is_array( $entries ) ) {
			return array();
		}

		foreach ( $entries as $entry ) {
			$validEntry = $this->validateEntry( $entry );

			if ( ! empty( $validEntry ) ) {
				$filteredEntries[] = $validEntry;
			}
		}

		return $filteredEntries;
	}

	/**
	 * @param $entry
	 *
	 * @return bool
	 */
	public function validateEntry($entry)
	{
		if ( ! (isset($entry['content']) && $entry['content']) ) {
			return false;
		}

		if ( isset( $entry['end'] ) && $entry['end'] && time() > strtotime( $entry['end'] ) ) {
			return false; // expired, do not show it
		}

		return true; // finally, return true if there are no issues with this notification
	}
}