PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / trunk
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score vtrunk
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / includes / classes / Extensions / Extensions.php

Extensions.php in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score trunk, at includes/classes/Extensions/Extensions.php

106 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Extension Loader
4 *
5 * @package PoweredCache\Extensions
6 */
7
8 namespace PoweredCache\Extensions;
9
10 use PoweredCache\Extensions\Cloudflare;
11 use PoweredCache\Extensions\Heartbeat\Heartbeat;
12
13 /**
14 * Class Extensions
15 */
16 class Extensions {
17
18 /**
19 * Plugin settings
20 *
21 * @var $settings
22 */
23 private $settings;
24
25 /**
26 * Placeholder constructor
27 */
28 public function __construct() {
29 }
30
31
32 /**
33 * Return an instance of the current class, create one if it doesn't exist
34 *
35 * @return object
36 * @since 1.0
37 */
38 public static function factory() {
39
40 static $instance;
41
42 if ( ! $instance ) {
43 $instance = new self();
44 $instance->setup();
45 }
46
47 return $instance;
48 }
49
50 /**
51 * Setup hooks
52 */
53 public function setup() {
54 $this->settings = \PoweredCache\Utils\get_settings();
55 add_action( 'plugins_loaded', [ $this, 'initialize_active_extensions' ] );
56 }
57
58 /**
59 * Init active extensions
60 */
61 public function initialize_active_extensions() {
62 if ( $this->is_load_cloudflare() ) {
63 Cloudflare\Cloudflare::factory();
64 }
65
66 if ( $this->is_load_heartbeat() ) {
67 Heartbeat::factory();
68 }
69
70 }
71
72 /**
73 * Whether load or not load CF
74 *
75 * @return bool
76 */
77 private function is_load_cloudflare() {
78 if ( ! $this->settings['enable_cloudflare'] ) {
79 return false;
80 }
81
82 if ( empty( $this->settings['cloudflare_zone'] ) ) {
83 return false;
84 }
85
86 if (
87 ( ! empty( $this->settings['cloudflare_email'] ) && ! empty( Cloudflare\Cloudflare::get_cf_api_key() ) )
88 || ( ! empty( Cloudflare\Cloudflare::get_cf_api_token() ) )
89 ) {
90 return true;
91 }
92
93 return false;
94 }
95
96 /**
97 * Whether load or not load heartbeat
98 *
99 * @return bool
100 */
101 private function is_load_heartbeat() {
102 return (bool) $this->settings['enable_heartbeat'];
103 }
104
105 }
106