diff --git a/includes/Classifai/Features/Feature.php b/includes/Classifai/Features/Feature.php index 1e69ba022..cd1e6a636 100644 --- a/includes/Classifai/Features/Feature.php +++ b/includes/Classifai/Features/Feature.php @@ -1119,6 +1119,29 @@ public function is_configured(): bool { return $is_configured; } + /** + * Returns whether the feature is configured with the specified provider or not. + * + * @param string $provider The specified provider. + * + * @return bool + */ + public function is_configured_with_provider( string $provider ): bool { + $settings = $this->get_settings(); + $provider_id = $settings['provider']; + $is_configured = false; + + if ( + ! empty( $settings ) && + $provider_id === $provider && + ! empty( $settings[ $provider_id ]['authenticated'] ) + ) { + $is_configured = true; + } + + return $is_configured; + } + /** * Can the feature be initialized? * diff --git a/includes/Classifai/Providers/AWS/AmazonPolly.php b/includes/Classifai/Providers/AWS/AmazonPolly.php index d2206b411..14b7bfcf9 100644 --- a/includes/Classifai/Providers/AWS/AmazonPolly.php +++ b/includes/Classifai/Providers/AWS/AmazonPolly.php @@ -47,19 +47,21 @@ public function render_provider_fields() { 'input_type' => 'text', 'default_value' => $settings['access_key_id'], 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Enter the AWS access key. Please follow the steps given here to generate AWS credentials.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Enter the AWS access key. Please follow the steps given here to generate AWS credentials.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey' ) ), - esc_url( 'https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_CreateAccessKey' ) - ), ] ); @@ -75,7 +77,9 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['secret_access_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, - 'description' => esc_html__( 'Enter the AWS secret access key.', 'classifai' ), + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + esc_html__( 'Enter the AWS secret access key.', 'classifai' ), ] ); @@ -91,12 +95,14 @@ public function render_provider_fields() { 'input_type' => 'text', 'default_value' => $settings['aws_region'], 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, - 'description' => wp_kses( - __( 'Enter the AWS Region. eg: us-east-1', 'classifai' ), - [ - 'code' => [], - ] - ), + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + wp_kses( + __( 'Enter the AWS Region. eg: us-east-1', 'classifai' ), + [ + 'code' => [], + ] + ), ] ); @@ -116,21 +122,23 @@ public function render_provider_fields() { ), 'default_value' => $settings['voice_engine'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Amazon Polly offers Long-Form, Neural and Standard text-to-speech voices. Please check the documentation to review pricing for Long-Form, Neural and Standard usage.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Amazon Polly offers Long-Form, Neural and Standard text-to-speech voices. Please check the documentation to review pricing for Long-Form, Neural and Standard usage.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://docs.aws.amazon.com/polly/latest/dg/long-form-voice-overview.html' ), + esc_url( 'https://docs.aws.amazon.com/polly/latest/dg/NTTS-main.html' ), + esc_url( 'https://aws.amazon.com/polly/pricing/' ) ), - esc_url( 'https://docs.aws.amazon.com/polly/latest/dg/long-form-voice-overview.html' ), - esc_url( 'https://docs.aws.amazon.com/polly/latest/dg/NTTS-main.html' ), - esc_url( 'https://aws.amazon.com/polly/pricing/' ) - ), ] ); diff --git a/includes/Classifai/Providers/Azure/ComputerVision.php b/includes/Classifai/Providers/Azure/ComputerVision.php index 3b7cd3d88..1a947a4d1 100644 --- a/includes/Classifai/Providers/Azure/ComputerVision.php +++ b/includes/Classifai/Providers/Azure/ComputerVision.php @@ -53,7 +53,9 @@ public function render_provider_fields() { 'label_for' => 'endpoint_url', 'input_type' => 'text', 'default_value' => $settings['endpoint_url'], - 'description' => __( 'Supported protocol and hostname endpoints, e.g., https://REGION.api.cognitive.microsoft.com or https://EXAMPLE.cognitiveservices.azure.com. This can look different based on your setting choices in Azure.', 'classifai' ), + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + __( 'Supported protocol and hostname endpoints, e.g., https://REGION.api.cognitive.microsoft.com or https://EXAMPLE.cognitiveservices.azure.com. This can look different based on your setting choices in Azure.', 'classifai' ), 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. ] ); diff --git a/includes/Classifai/Providers/Azure/OpenAI.php b/includes/Classifai/Providers/Azure/OpenAI.php index 7a542a2b7..ddacf4d05 100644 --- a/includes/Classifai/Providers/Azure/OpenAI.php +++ b/includes/Classifai/Providers/Azure/OpenAI.php @@ -78,7 +78,9 @@ public function render_provider_fields() { 'label_for' => 'endpoint_url', 'input_type' => 'text', 'default_value' => $settings['endpoint_url'], - 'description' => __( 'Supported protocol and hostname endpoints, e.g., https://EXAMPLE.openai.azure.com.', 'classifai' ), + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + __( 'Supported protocol and hostname endpoints, e.g., https://EXAMPLE.openai.azure.com.', 'classifai' ), 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, ] ); @@ -109,7 +111,9 @@ public function render_provider_fields() { 'label_for' => 'deployment', 'input_type' => 'text', 'default_value' => $settings['deployment'], - 'description' => __( 'Custom name you chose for your deployment when you deployed a model.', 'classifai' ), + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + __( 'Custom name you chose for your deployment when you deployed a model.', 'classifai' ), 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, ] ); diff --git a/includes/Classifai/Providers/Azure/Personalizer.php b/includes/Classifai/Providers/Azure/Personalizer.php index da6663141..99a00ecd3 100644 --- a/includes/Classifai/Providers/Azure/Personalizer.php +++ b/includes/Classifai/Providers/Azure/Personalizer.php @@ -110,20 +110,22 @@ public function render_provider_fields() { 'input_type' => 'text', 'default_value' => $settings['endpoint_url'], 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - // translators: 1 - link to create a Personalizer resource; 2 - link to GitHub issue. - __( 'Azure AI Personalizer Endpoint; create a Personalizer resource in the Azure portal to get your key and endpoint. Note that as of September 2023, it is no longer possible to create this resource. Previously created Personalizer resources can still be used.', 'classifai' ), - array( - 'a' => array( - 'href' => array(), - 'target' => array(), - ), - ) + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + // translators: 1 - link to create a Personalizer resource; 2 - link to GitHub issue. + __( 'Azure AI Personalizer Endpoint; create a Personalizer resource in the Azure portal to get your key and endpoint. Note that as of September 2023, it is no longer possible to create this resource. Previously created Personalizer resources can still be used.', 'classifai' ), + array( + 'a' => array( + 'href' => array(), + 'target' => array(), + ), + ) + ), + 'https://portal.azure.com/#create/Microsoft.CognitiveServicesPersonalizer', + 'https://learn.microsoft.com/en-us/azure/ai-services/personalizer/' ), - 'https://portal.azure.com/#create/Microsoft.CognitiveServicesPersonalizer', - 'https://learn.microsoft.com/en-us/azure/ai-services/personalizer/' - ), ] ); diff --git a/includes/Classifai/Providers/Azure/Speech.php b/includes/Classifai/Providers/Azure/Speech.php index 13a13457d..8e66b441d 100644 --- a/includes/Classifai/Providers/Azure/Speech.php +++ b/includes/Classifai/Providers/Azure/Speech.php @@ -57,7 +57,9 @@ public function render_provider_fields() { 'label_for' => 'endpoint_url', 'input_type' => 'text', 'default_value' => $settings['endpoint_url'], - 'description' => __( 'Text to Speech region endpoint, e.g., https://LOCATION.tts.speech.microsoft.com/. Replace LOCATION with the Location/Region you selected for the resource in Azure.', 'classifai' ), + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + __( 'Text to Speech region endpoint, e.g., https://LOCATION.tts.speech.microsoft.com/. Replace LOCATION with the Location/Region you selected for the resource in Azure.', 'classifai' ), 'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. ] ); diff --git a/includes/Classifai/Providers/GoogleAI/GeminiAPI.php b/includes/Classifai/Providers/GoogleAI/GeminiAPI.php index f6f6c3923..a8580065c 100644 --- a/includes/Classifai/Providers/GoogleAI/GeminiAPI.php +++ b/includes/Classifai/Providers/GoogleAI/GeminiAPI.php @@ -63,19 +63,21 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an Google AI (Gemini API) key? Get an API key now.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an Google AI (Gemini API) key? Get an API key now.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://makersuite.google.com/app/apikey' ) ), - esc_url( 'https://makersuite.google.com/app/apikey' ) - ), ] ); diff --git a/includes/Classifai/Providers/OpenAI/ChatGPT.php b/includes/Classifai/Providers/OpenAI/ChatGPT.php index 5b7dc640a..948eabcf7 100644 --- a/includes/Classifai/Providers/OpenAI/ChatGPT.php +++ b/includes/Classifai/Providers/OpenAI/ChatGPT.php @@ -69,19 +69,21 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://platform.openai.com/signup' ) ), - esc_url( 'https://platform.openai.com/signup' ) - ), ] ); diff --git a/includes/Classifai/Providers/OpenAI/DallE.php b/includes/Classifai/Providers/OpenAI/DallE.php index 7ee4fac57..aaf3d63de 100644 --- a/includes/Classifai/Providers/OpenAI/DallE.php +++ b/includes/Classifai/Providers/OpenAI/DallE.php @@ -67,19 +67,21 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://platform.openai.com/signup' ) ), - esc_url( 'https://platform.openai.com/signup' ) - ), ] ); diff --git a/includes/Classifai/Providers/OpenAI/Embeddings.php b/includes/Classifai/Providers/OpenAI/Embeddings.php index ef30d80ce..76643972e 100644 --- a/includes/Classifai/Providers/OpenAI/Embeddings.php +++ b/includes/Classifai/Providers/OpenAI/Embeddings.php @@ -215,19 +215,21 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://platform.openai.com/signup' ) ), - esc_url( 'https://platform.openai.com/signup' ) - ), ] ); diff --git a/includes/Classifai/Providers/OpenAI/Moderation.php b/includes/Classifai/Providers/OpenAI/Moderation.php index 176dcf28f..b4858f886 100644 --- a/includes/Classifai/Providers/OpenAI/Moderation.php +++ b/includes/Classifai/Providers/OpenAI/Moderation.php @@ -55,19 +55,21 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://platform.openai.com/signup' ) ), - esc_url( 'https://platform.openai.com/signup' ) - ), ] ); diff --git a/includes/Classifai/Providers/OpenAI/TextToSpeech.php b/includes/Classifai/Providers/OpenAI/TextToSpeech.php index 873f1d4ef..1b44702f1 100644 --- a/includes/Classifai/Providers/OpenAI/TextToSpeech.php +++ b/includes/Classifai/Providers/OpenAI/TextToSpeech.php @@ -48,19 +48,21 @@ public function render_provider_fields(): void { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://platform.openai.com/signup' ) ), - esc_url( 'https://platform.openai.com/signup' ) - ), ] ); @@ -78,18 +80,20 @@ public function render_provider_fields(): void { 'tts-1-hd' => __( 'Text-to-speech 1 HD (Optimized for quality)', 'classifai' ), ], 'default_value' => $settings['tts_model'], - 'description' => sprintf( - wp_kses( - __( 'Select a model depending on your requirement.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + __( 'Select a model depending on your requirement.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], ], - ], + ), + esc_url( 'https://platform.openai.com/docs/models/tts' ) ), - esc_url( 'https://platform.openai.com/docs/models/tts' ) - ), 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, ] ); @@ -112,18 +116,20 @@ public function render_provider_fields(): void { 'shimmer' => __( 'Shimmer (female)', 'classifai' ), ], 'default_value' => $settings['voice'], - 'description' => sprintf( - wp_kses( - __( 'Select the speech voice.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + __( 'Select the speech voice.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], ], - ], + ), + esc_url( 'https://platform.openai.com/docs/guides/text-to-speech/voice-options' ) ), - esc_url( 'https://platform.openai.com/docs/guides/text-to-speech/voice-options' ) - ), 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, ] ); diff --git a/includes/Classifai/Providers/OpenAI/Whisper.php b/includes/Classifai/Providers/OpenAI/Whisper.php index 6e8072c4c..b80fd923b 100644 --- a/includes/Classifai/Providers/OpenAI/Whisper.php +++ b/includes/Classifai/Providers/OpenAI/Whisper.php @@ -93,19 +93,21 @@ public function render_provider_fields() { 'input_type' => 'password', 'default_value' => $settings['api_key'], 'class' => 'classifai-provider-field hidden provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - /* translators: %1$s is replaced with the OpenAI sign up URL */ - __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is replaced with the OpenAI sign up URL */ + __( 'Don\'t have an OpenAI account yet? Sign up for one in order to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://platform.openai.com/signup' ) ), - esc_url( 'https://platform.openai.com/signup' ) - ), ] ); diff --git a/includes/Classifai/Providers/Watson/NLU.php b/includes/Classifai/Providers/Watson/NLU.php index 251c2337f..e38473446 100644 --- a/includes/Classifai/Providers/Watson/NLU.php +++ b/includes/Classifai/Providers/Watson/NLU.php @@ -121,20 +121,22 @@ public function render_provider_fields() { 'input_type' => 'password', 'large' => true, 'class' => 'classifai-provider-field provider-scope-' . static::ID, // Important to add this. - 'description' => sprintf( - wp_kses( - /* translators: %1$s is the link to register for an IBM Cloud account, %2$s is the link to setup the NLU service */ - __( 'Don\'t have an IBM Cloud account yet? Register for one and set up a Natural Language Understanding Resource to get your API key.', 'classifai' ), - [ - 'a' => [ - 'href' => [], - 'title' => [], - ], - ] + 'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ? + '' : + sprintf( + wp_kses( + /* translators: %1$s is the link to register for an IBM Cloud account, %2$s is the link to setup the NLU service */ + __( 'Don\'t have an IBM Cloud account yet? Register for one and set up a Natural Language Understanding Resource to get your API key.', 'classifai' ), + [ + 'a' => [ + 'href' => [], + 'title' => [], + ], + ] + ), + esc_url( 'https://cloud.ibm.com/registration' ), + esc_url( 'https://cloud.ibm.com/catalog/services/natural-language-understanding' ) ), - esc_url( 'https://cloud.ibm.com/registration' ), - esc_url( 'https://cloud.ibm.com/catalog/services/natural-language-understanding' ) - ), ] );