# powered-cache/2.0.1/includes/classes/Extensions/Extensions.php

Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed &amp; Web Vitals Score, version 2.0.1. 107 lines.

- Page: https://pluginprobe.com/plugins/powered-cache/2.0.1/code/includes/classes/Extensions/Extensions.php
- Raw: https://pluginprobe.com/plugins/powered-cache/2.0.1/raw/includes/classes/Extensions/Extensions.php
- Modified: 2021-08-26T10:31:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/powered-cache/2.0.1/code/includes/classes/Extensions/Extensions.php#L10-L20`.

```php
<?php
/**
 * Extension Loader
 *
 * @package PoweredCache\Extensions
 */

namespace PoweredCache\Extensions;

use PoweredCache\Extensions\Cloudflare;
use PoweredCache\Extensions\Heartbeat\Heartbeat;

/**
 * Class Extensions
 */
class Extensions {

	/**
	 * Plugin settings
	 *
	 * @var $settings
	 */
	private $settings;

	/**
	 * Placeholder constructor
	 */
	public function __construct() {
	}


	/**
	 * Return an instance of the current class, create one if it doesn't exist
	 *
	 * @return object
	 * @since  1.0
	 */
	public static function factory() {

		static $instance;

		if ( ! $instance ) {
			$instance = new self();
			$instance->setup();
		}

		return $instance;
	}

	/**
	 * Setup hooks
	 */
	public function setup() {
		$this->settings = \PoweredCache\Utils\get_settings();
		add_action( 'plugins_loaded', [ $this, 'initialize_active_extensions' ] );
	}

	/**
	 * Init active extensions
	 */
	public function initialize_active_extensions() {
		if ( $this->is_load_cloudflare() ) {
			Cloudflare\Cloudflare::factory();
		}

		if ( $this->is_load_heartbeat() ) {
			Heartbeat::factory();
		}

	}

	/**
	 * Whether load or not load CF
	 *
	 * @return bool
	 */
	private function is_load_cloudflare() {
		if ( ! $this->settings['enable_cloudflare'] ) {
			return false;
		}

		$required_settings = [
			'cloudflare_email',
			'cloudflare_api_key',
			'cloudflare_zone',
		];

		foreach ( $required_settings as $field ) {
			if ( empty( $this->settings[ $field ] ) ) {
				return false;
			}
		}

		return true;
	}

	/**
	 * Whether load or not load heartbeat
	 *
	 * @return bool
	 */
	private function is_load_heartbeat() {
		return (bool) $this->settings['enable_heartbeat'];
	}

}

```
