From 27ecf8611409bf1ec2ebf96359a0b13dc7d4c3b9 Mon Sep 17 00:00:00 2001 From: Mehmood Ahmad <31419912+mehmoodak@users.noreply.github.com> Date: Sat, 14 Oct 2023 02:56:55 +0500 Subject: [PATCH] Removes hardcoded VIP_PARSELY_ENABLED constant for FedRAMP sites (#4935) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ➖ REMOVE: VIP_PARSELY_ENABLED constant for FedRAMP sites * 🔨 REFACTOR: is_active_via_vip function --- 000-vip-init.php | 5 ---- integrations/integration-vip-config.php | 38 ++++++++++--------------- integrations/parsely.php | 6 ++-- 3 files changed, 18 insertions(+), 31 deletions(-) diff --git a/000-vip-init.php b/000-vip-init.php index b6bc86d1bdc..8c851c996a4 100644 --- a/000-vip-init.php +++ b/000-vip-init.php @@ -133,11 +133,6 @@ if ( ! defined( 'VIP_JETPACK_SKIP_LOAD' ) ) { define( 'VIP_JETPACK_SKIP_LOAD', true ); } - - // FedRAMP sites do not load Parse.ly by default - if ( ! defined( 'VIP_PARSELY_ENABLED' ) ) { - define( 'VIP_PARSELY_ENABLED', false ); - } } $private_dir_path = WP_CONTENT_DIR . '/private'; // Local fallback diff --git a/integrations/integration-vip-config.php b/integrations/integration-vip-config.php index a35a78ee3eb..e6ff61af30a 100644 --- a/integrations/integration-vip-config.php +++ b/integrations/integration-vip-config.php @@ -109,32 +109,24 @@ protected function get_vip_config_from_file( string $slug ) { * @private */ public function is_active_via_vip(): bool { - // Return false if blocked on org. - if ( $this->get_value_from_config( 'org', 'status' ) === Org_Integration_Status::BLOCKED ) { - return false; - } - - $env_status = $this->get_value_from_config( 'env', 'status' ); - - // Return false if blocked on env. - if ( Env_Integration_Status::BLOCKED === $env_status ) { - return false; - } - - // Look into network_sites config before because if not present we will fallback to env config. - $network_site_status = $this->get_value_from_config( 'network_sites', 'status' ); - - if ( Env_Integration_Status::ENABLED === $network_site_status ) { - return true; - } + return Env_Integration_Status::ENABLED === $this->get_site_status(); + } - // Return false if status is defined but other than enabled. If status is not defined then fallback to env config. - if ( null !== $network_site_status ) { - return false; + /** + * Get site status. + * + * @return string|null + * + * @private + */ + public function get_site_status() { + if ( $this->get_value_from_config( 'org', 'status' ) === Org_Integration_Status::BLOCKED ) { + return Org_Integration_Status::BLOCKED; } - // Return true if enabled on env. - return Env_Integration_Status::ENABLED === $env_status; + // Look into network_sites config before and then fallback to env config. + return $this->get_value_from_config( 'network_sites', 'status' ) ?? + $this->get_value_from_config( 'env', 'status' ); } /** diff --git a/integrations/parsely.php b/integrations/parsely.php index c7d08dc607c..89bd75c2286 100644 --- a/integrations/parsely.php +++ b/integrations/parsely.php @@ -28,9 +28,9 @@ public function is_loaded(): bool { */ public function load(): void { // Return if the integration is already loaded. - // - // In activate() method we do make sure to not activate the integration if its already loaded - // but still adding it here as a safety measure i.e. if load() is called directly. + // + // In activate() method we do make sure to not activate the integration if its already loaded + // but still adding it here as a safety measure i.e. if load() is called directly. if ( $this->is_loaded() ) { return; }