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']; } }