diff --git a/integrations/integration.php b/integrations/integration.php index 9c44d3eeb41..c1b1abeb704 100644 --- a/integrations/integration.php +++ b/integrations/integration.php @@ -84,6 +84,15 @@ abstract class Integration { */ public bool $is_active_by_customer = false; + /** + * Name of the filter which we will use to setup the integration configs. + * + * As of now there is no default so each integration will define its own filter in their class. + * + * @var string + */ + protected string $integration_configs_filter_name = ''; + /** * Constructor. * @@ -155,7 +164,7 @@ private function set_vip_config(): void { } /** - * Returns true if the integration is active by VIP. + * Returns true if the integration is active by VIP and setup plugin configs which are provided by VIP. * * @return bool */ @@ -172,16 +181,36 @@ private function is_active_by_vip(): bool { return false; } - // Check for network-site enablement if multisite. + // Check network site enablement if multisite. if ( is_multisite() ) { if ( is_network_admin() ) { return false; } - return $this->get_value_from_vip_config( 'network_sites', 'status' ) === Site_Integration_Status::ENABLED; + // If enabled on network site then set credentials via filter and return true. + if ( $this->get_value_from_vip_config( 'network_sites', 'status' ) === Site_Integration_Status::ENABLED ) { + if ( '' !== $this->integration_configs_filter_name ) { + add_filter( $this->integration_configs_filter_name, function() { + return $this->get_value_from_vip_config( 'network_sites', 'configs' ); + } ); + } + + return true; + } + } + + // If enabled on site then set credentials via filter and return true. + if ( Site_Integration_Status::ENABLED === $site_status ) { + if ( '' !== $this->integration_configs_filter_name ) { + add_filter( $this->integration_configs_filter_name, function() { + return $this->get_value_from_vip_config( 'site', 'configs' ); + } ); + } + + return true; } - return Site_Integration_Status::ENABLED === $site_status; // Return site status if not multisite. + return false; } /** @@ -190,9 +219,9 @@ private function is_active_by_vip(): bool { * @param string $config_type Type of the config whose data is needed i.e. client, site, network-sites etc. * @param string $key Key of the config from which we have to extract the data. * - * @return string + * @return string|array */ - private function get_value_from_vip_config( string $config_type, string $key ): string { + private function get_value_from_vip_config( string $config_type, string $key ) { if ( ! isset( $this->vip_config[ $config_type ] ) ) { return ''; } diff --git a/integrations/parsely.php b/integrations/parsely.php index cd85e877ea3..e331f0aea43 100644 --- a/integrations/parsely.php +++ b/integrations/parsely.php @@ -13,6 +13,13 @@ * @private */ class ParselyIntegration extends Integration { + /** + * Name of the filter which we will use to setup the plugin configs. + * + * @var string + */ + protected string $integration_configs_filter_name = 'wp_parsely_credentials'; + /** * Applies hooks to load plugin. * diff --git a/vip-integrations.php b/vip-integrations.php index 96be462aa68..1fd21af7ec5 100644 --- a/vip-integrations.php +++ b/vip-integrations.php @@ -1,7 +1,7 @@