Skip to content

Commit

Permalink
Merge pull request #770 from 10up/feature/hide-help-text-if-feature-e…
Browse files Browse the repository at this point in the history
…nabled

Conditional Display of Helper Text for AI Provider Account Creation
  • Loading branch information
jeffpaul authored May 30, 2024
2 parents 1179e74 + 0d09d53 commit c6af998
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 167 deletions.
23 changes: 23 additions & 0 deletions includes/Classifai/Features/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?
*
Expand Down
74 changes: 41 additions & 33 deletions includes/Classifai/Providers/AWS/AmazonPolly.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a title="AWS documentation" href="%1$s">here</a> 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 <a title="AWS documentation" href="%1$s">here</a> 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' )
),
]
);

Expand All @@ -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' ),
]
);

Expand All @@ -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: <code>us-east-1</code>', 'classifai' ),
[
'code' => [],
]
),
'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ?
'' :
wp_kses(
__( 'Enter the AWS Region. eg: <code>us-east-1</code>', 'classifai' ),
[
'code' => [],
]
),
]
);

Expand All @@ -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 <a href="%1$s">Long-Form</a>, <a href="%2$s">Neural</a> and Standard text-to-speech voices. Please check the <a title="Pricing" href="%3$s">documentation</a> 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 <a href="%1$s">Long-Form</a>, <a href="%2$s">Neural</a> and Standard text-to-speech voices. Please check the <a title="Pricing" href="%3$s">documentation</a> 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/' )
),
]
);

Expand Down
4 changes: 3 additions & 1 deletion includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -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., <code>https://REGION.api.cognitive.microsoft.com</code> or <code>https://EXAMPLE.cognitiveservices.azure.com</code>. 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., <code>https://REGION.api.cognitive.microsoft.com</code> or <code>https://EXAMPLE.cognitiveservices.azure.com</code>. 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.
]
);
Expand Down
8 changes: 6 additions & 2 deletions includes/Classifai/Providers/Azure/OpenAI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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., <code>https://EXAMPLE.openai.azure.com</code>.', 'classifai' ),
'description' => $this->feature_instance->is_configured_with_provider( static::ID ) ?
'' :
__( 'Supported protocol and hostname endpoints, e.g., <code>https://EXAMPLE.openai.azure.com</code>.', 'classifai' ),
'class' => 'large-text classifai-provider-field hidden provider-scope-' . static::ID,
]
);
Expand Down Expand Up @@ -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,
]
);
Expand Down
28 changes: 15 additions & 13 deletions includes/Classifai/Providers/Azure/Personalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; <a href="%1$s" target="_blank">create a Personalizer resource</a> in the Azure portal to get your key and endpoint. Note that <a href="%2$s" target="_blank">as of September 2023</a>, 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; <a href="%1$s" target="_blank">create a Personalizer resource</a> in the Azure portal to get your key and endpoint. Note that <a href="%2$s" target="_blank">as of September 2023</a>, 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/'
),
]
);

Expand Down
4 changes: 3 additions & 1 deletion includes/Classifai/Providers/Azure/Speech.php
Original file line number Diff line number Diff line change
Expand Up @@ -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., <code>https://LOCATION.tts.speech.microsoft.com/</code>. Replace <code>LOCATION</code> 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., <code>https://LOCATION.tts.speech.microsoft.com/</code>. Replace <code>LOCATION</code> 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.
]
);
Expand Down
26 changes: 14 additions & 12 deletions includes/Classifai/Providers/GoogleAI/GeminiAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -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? <a title="Get an API key" href="%1$s">Get an API key</a> 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? <a title="Get an API key" href="%1$s">Get an API key</a> now.', 'classifai' ),
[
'a' => [
'href' => [],
'title' => [],
],
]
),
esc_url( 'https://makersuite.google.com/app/apikey' )
),
esc_url( 'https://makersuite.google.com/app/apikey' )
),
]
);

Expand Down
26 changes: 14 additions & 12 deletions includes/Classifai/Providers/OpenAI/ChatGPT.php
Original file line number Diff line number Diff line change
Expand Up @@ -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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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' )
),
]
);

Expand Down
26 changes: 14 additions & 12 deletions includes/Classifai/Providers/OpenAI/DallE.php
Original file line number Diff line number Diff line change
Expand Up @@ -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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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' )
),
]
);

Expand Down
26 changes: 14 additions & 12 deletions includes/Classifai/Providers/OpenAI/Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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' )
),
]
);

Expand Down
26 changes: 14 additions & 12 deletions includes/Classifai/Providers/OpenAI/Moderation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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? <a title="Sign up for an OpenAI account" href="%1$s">Sign up for one</a> 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' )
),
]
);

Expand Down
Loading

0 comments on commit c6af998

Please sign in to comment.