diff --git a/integrations/integration-vip-config.php b/integrations/integration-vip-config.php index 45714eed92..c1c982d262 100644 --- a/integrations/integration-vip-config.php +++ b/integrations/integration-vip-config.php @@ -82,25 +82,34 @@ protected function get_vip_config_from_file( string $slug ) { ? constant( 'WPVIP_INTEGRATIONS_CONFIG_DIR' ) : ABSPATH . 'config/integrations-config'; $config_file_name = $slug . '-config.php'; - $config_file_path = $config_file_directory . '/' . $config_file_name; - - /** - * Clear cache to always read data from latest config file. - * - * Kubernetes ConfigMap updates the file via symlink instead of actually replacing the file and - * PHP cache can hold a reference to the old symlink that can cause fatal if we use require - * on it. - */ - clearstatcache( true, $config_file_directory . '/' . $config_file_name ); - // Clears cache for files created by k8s ConfigMap. - clearstatcache( true, $config_file_directory . '/..data' ); - clearstatcache( true, $config_file_directory . '/..data/' . $config_file_name ); - - if ( ! is_readable( $config_file_path ) ) { - return null; + $config_file_path_orig = $config_file_directory . '/' . $config_file_name; + + $config_file_path = apply_filters( 'vip_integrations_config_file_path', $config_file_path_orig, $slug ); + $config_data = apply_filters( 'vip_integrations_pre_load_config', null, $config_file_path, $slug ); + + if ( is_null( $config_data ) ) { + if ( $config_file_path_orig === $config_file_path ) { + /** + * Clear cache to always read data from latest config file. + * + * Kubernetes ConfigMap updates the file via symlink instead of actually replacing the file and + * PHP cache can hold a reference to the old symlink that can cause fatal if we use require + * on it. + */ + clearstatcache( true, $config_file_directory . '/' . $config_file_name ); + // Clears cache for files created by k8s ConfigMap. + clearstatcache( true, $config_file_directory . '/..data' ); + clearstatcache( true, $config_file_directory . '/..data/' . $config_file_name ); + } + + if ( ! is_readable( $config_file_path ) ) { + return null; + } + + $config_data = require $config_file_path; } - return require $config_file_path; + return $config_data; } /** diff --git a/integrations/jetpack.php b/integrations/jetpack.php new file mode 100644 index 0000000000..c61665ba87 --- /dev/null +++ b/integrations/jetpack.php @@ -0,0 +1,34 @@ +get_env_config()['version'] ) ) { + $this->version = $this->get_env_config()['version']; + } elseif ( defined( 'VIP_JETPACK_PINNED_VERSION' ) ) { + $this->version = constant( 'VIP_JETPACK_PINNED_VERSION' ); + } else { + $this->version = vip_default_jetpack_version(); + } + } + + public function load(): void { + if ( $this->is_loaded() ) { + return; + } + + // Pass through to the old code for now which will respect all existing constants + if ( ! defined( 'WP_INSTALLING' ) ) { + vip_jetpack_load(); + } + } +} diff --git a/vip-integrations.php b/vip-integrations.php index 6cc22c4102..c7ef7664b6 100644 --- a/vip-integrations.php +++ b/vip-integrations.php @@ -24,11 +24,19 @@ require_once __DIR__ . '/integrations/vip-governance.php'; require_once __DIR__ . '/integrations/enterprise-search.php'; +if ( file_exists( __DIR__ . '/integrations/jetpack.php' ) ) { + require_once __DIR__ . '/integrations/jetpack.php'; +} + // Register VIP integrations here. IntegrationsSingleton::instance()->register( new BlockDataApiIntegration( 'block-data-api' ) ); IntegrationsSingleton::instance()->register( new ParselyIntegration( 'parsely' ) ); IntegrationsSingleton::instance()->register( new VipGovernanceIntegration( 'vip-governance' ) ); IntegrationsSingleton::instance()->register( new EnterpriseSearchIntegration( 'enterprise-search' ) ); + +if ( class_exists( __NAMESPACE__ . '\\JetpackIntegration' ) ) { + IntegrationsSingleton::instance()->register( new JetpackIntegration( 'jetpack' ) ); +} // @codeCoverageIgnoreEnd /**