From b4abc53a1281f1980bb4ee4af3e97454a2443628 Mon Sep 17 00:00:00 2001 From: Mehmood Ahmad <31419912+mehmoodak@users.noreply.github.com> Date: Wed, 5 Jul 2023 18:44:45 +0500 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20ADDS:=20support=20for=20setting=20u?= =?UTF-8?q?p=20integration=20configs=20via=20provided=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- integrations/integration.php | 41 ++++++++++++++++++++++++++++++------ integrations/parsely.php | 7 ++++++ vip-integrations.php | 2 +- wp-parsely-3.8 | 1 + 4 files changed, 44 insertions(+), 7 deletions(-) create mode 160000 wp-parsely-3.8 diff --git a/integrations/integration.php b/integrations/integration.php index 9c44d3eeb4..c1b1abeb70 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 cd85e877ea..e331f0aea4 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 96be462aa6..1fd21af7ec 100644 --- a/vip-integrations.php +++ b/vip-integrations.php @@ -1,7 +1,7 @@