Skip to content

Commit

Permalink
Removes hardcoded VIP_PARSELY_ENABLED constant for FedRAMP sites (#4935)
Browse files Browse the repository at this point in the history
* ➖ REMOVE: VIP_PARSELY_ENABLED constant for FedRAMP sites

* 🔨 REFACTOR: is_active_via_vip function
  • Loading branch information
mehmoodak authored and andrea-sdl committed Oct 19, 2023
1 parent 53e266a commit 27ecf86
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 31 deletions.
5 changes: 0 additions & 5 deletions 000-vip-init.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 15 additions & 23 deletions integrations/integration-vip-config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}

/**
Expand Down
6 changes: 3 additions & 3 deletions integrations/parsely.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 27ecf86

Please sign in to comment.