HEX
Server: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
System: Linux atalantini.com 3.10.0-1127.13.1.el7.x86_64 #1 SMP Tue Jun 23 15:46:38 UTC 2020 x86_64
User: root (0)
PHP: 7.2.34
Disabled: NONE
Upload Files
File: //opt/plugins/countdown-builder/classes/IncludeManager.php
<?php
namespace ycd;
use \WP_Query;

class IncludeManager {
	
	private $allowedCountdowns;
	
	public function __construct() {
		$this->init();
	}
	
	public function setAllowedCountdowns($allowedCountdowns)
	{
		$this->allowedCountdowns = $allowedCountdowns;
	}
	
	public function getAllowedCountdowns()
	{
		return $this->allowedCountdowns;
	}
	
	public function init() {
		$countdownPosts = new WP_Query(
			array(
				'post_type'      => YCD_COUNTDOWN_POST_TYPE,
				'posts_per_page' => - 1
			)
		);
		$posts = array();
		
		while ($countdownPosts->have_posts()) {
			$countdownPosts->next_post();
			$countdownPost = $countdownPosts->post;
			
			if (empty($countdownPost) || empty($countdownPost->ID) || !Countdown::isActivePost($countdownPost->ID)) {
				continue;
			}
			$countdownObj = Countdown::find($countdownPost->ID);

			if(empty($countdownObj) || !is_object($countdownObj)) {
				continue;
			}
			$isAllow = Countdown::allowToLoad($countdownPost, $countdownObj);
			
			if(!$isAllow) {
				continue;
			}
			
			$posts[] = $countdownObj;
		}
		$this->setAllowedCountdowns($posts);
		$this->includeCountdowns();
	}
	
	private function includeCountdowns() {
		$countdowns = $this->getAllowedCountdowns();

		if(empty($countdowns)) {
			return false;
		}
		
		foreach($countdowns as $countdown) {
			$this->includeCountdown($countdown);
		}
		
		return true;
	}
	
	private function includeCountdown($countdown) {
		$content = $countdown->addToContent();

		add_action('wp_head',function() use ($content) {
			echo $content;
		});
	}
}