Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addressing TODO from https://github.com/10up/classifai/issues/260 ComputerVision::reset_settings() #264

Merged
merged 8 commits into from
May 7, 2021
55 changes: 38 additions & 17 deletions includes/Classifai/Providers/Azure/ComputerVision.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,27 @@ public function __construct( $service ) {
* Resets settings for the ComputerVision provider.
*/
public function reset_settings() {
// TODO: Implement reset_settings() method.
update_option( $this->get_option_name(), $this->get_default_settings() );
}

/**
* Default settings for ComputerVision
*
* @return array
*/
private function get_default_settings() {
return [
'valid' => false,
'url' => '',
'api_key' => '',
'enable_image_captions' => true,
'enable_image_tagging' => true,
'enable_smart_cropping' => false,
'enable_ocr' => false,
'caption_threshold' => 75,
'tag_threshold' => 70,
'image_tag_taxonomy' => 'classifai-image-tags',
];
}

/**
Expand Down Expand Up @@ -611,16 +631,18 @@ protected function generate_image_tags( $tags, $attachment_id ) {
*/
public function setup_fields_sections() {
add_settings_section( $this->get_option_name(), $this->provider_service_name, '', $this->get_option_name() );
$default_settings = $this->get_default_settings();
add_settings_field(
'url',
esc_html__( 'Endpoint URL', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'url',
'input_type' => 'text',
'description' => __( 'e.g. <code>https://REGION.api.cognitive.microsoft.com/</code>', 'classifai' ),
'label_for' => 'url',
'input_type' => 'text',
'default_value' => $default_settings['url'],
'description' => __( 'e.g. <code>https://REGION.api.cognitive.microsoft.com/</code>', 'classifai' ),
]
);
add_settings_field(
Expand All @@ -630,8 +652,9 @@ public function setup_fields_sections() {
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'api_key',
'input_type' => 'password',
'label_for' => 'api_key',
'input_type' => 'password',
'default_value' => $default_settings['api_key'],
]
);
add_settings_field(
Expand All @@ -643,7 +666,7 @@ public function setup_fields_sections() {
[
'label_for' => 'enable_image_captions',
'input_type' => 'checkbox',
'default_value' => true,
'default_value' => $default_settings['enable_image_captions'],
'description' => __( 'Images will be captioned with alt text upon upload', 'classifai' ),
]
);
Expand All @@ -656,7 +679,7 @@ public function setup_fields_sections() {
[
'label_for' => 'caption_threshold',
'input_type' => 'number',
'default_value' => 75,
'default_value' => $default_settings['caption_threshold'],
'description' => __( 'Minimum confidence score for automatically applied image captions, numeric value from 0-100. Recommended to be set to at least 75.', 'classifai' ),
]
);
Expand All @@ -669,7 +692,7 @@ public function setup_fields_sections() {
[
'label_for' => 'enable_image_tagging',
'input_type' => 'checkbox',
'default_value' => true,
'default_value' => $default_settings['enable_image_tagging'],
'description' => __( 'Images will be tagged upon upload', 'classifai' ),
]
);
Expand All @@ -682,11 +705,10 @@ public function setup_fields_sections() {
[
'label_for' => 'tag_threshold',
'input_type' => 'number',
'default_value' => 70,
'default_value' => $default_settings['tag_threshold'],
'description' => __( 'Minimum confidence score for automatically applied image tags, numeric value from 0-100. Recommended to be set to at least 70.', 'classifai' ),
]
);

// What taxonomy should we tag images with?
$attachment_taxonomies = get_object_taxonomies( 'attachment', 'objects' );
$options = [];
Expand All @@ -700,11 +722,11 @@ public function setup_fields_sections() {
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'image_tag_taxonomy',
'options' => $options,
'label_for' => 'image_tag_taxonomy',
'options' => $options,
'default_value' => $default_settings['image_tag_taxonomy'],
]
);

add_settings_field(
'enable-smart-cropping',
esc_html__( 'Enable smart cropping', 'classifai' ),
Expand All @@ -714,14 +736,13 @@ public function setup_fields_sections() {
[
'label_for' => 'enable_smart_cropping',
'input_type' => 'checkbox',
'default_value' => false,
'default_value' => $default_settings['enable_smart_cropping'],
'description' => __(
'Crop images around a region of interest identified by ComputerVision',
'classifai'
),
]
);

add_settings_field(
'enable-ocr',
esc_html__( 'Enable OCR', 'classifai' ),
Expand All @@ -731,7 +752,7 @@ public function setup_fields_sections() {
[
'label_for' => 'enable_ocr',
'input_type' => 'checkbox',
'default_value' => false,
'default_value' => $default_settings['enable_ocr'],
'description' => __(
'Detect text in an image and store that as post content',
'classifai'
Expand Down