PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 2.0
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v2.0
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 2.0, at includes/classes/Extensions/Extensions.php

107 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 $required_settings = [
83 'cloudflare_email',
84 'cloudflare_api_key',
85 'cloudflare_zone',
86 ];
87
88 foreach ( $required_settings as $field ) {
89 if ( empty( $this->settings[ $field ] ) ) {
90 return false;
91 }
92 }
93
94 return true;
95 }
96
97 /**
98 * Whether load or not load heartbeat
99 *
100 * @return bool
101 */
102 private function is_load_heartbeat() {
103 return (bool) $this->settings['enable_heartbeat'];
104 }
105
106 }
107