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

Conversation

ActuallyConnor
Copy link
Contributor

Description of the Change

Addressing TODO from #260

public function reset_settings() {
    // TODO: Implement reset_settings() method.
}

Alternate Designs

n/a

Benefits

Addressing issue related to resolving TODOs in the repository. Presumably this function will allow for a quick reset of the settings back to the default so that the user doesn't have to go through resetting settings manually.

Possible Drawbacks

none identified

Verification Process

I looked the serialized array data in the database for what is there when the plugin is activated upon a fresh install and modelled the reset_settings() method off of that data and the includes/Classifai/Providers/Watson/NLU.php reset_settings() method.

Not sure if there is more that you are looking for or if you would also like a button on this page that triggers an event to reset the settings. If there is something like that you are looking for please let me know :)

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

#260

Changelog Entry

Addressed TODO to implement ComputerVision::reset_settings() method

I looked the serialized array data in the database for what is there when the plugin is activated upon a fresh install and modelled the reset_settings() method off of that data and the includes/Classifai/Providers/Watson/NLU.php reset_settings() method.

Not sure if there is more that you are looking for or if you would also like a button on this page that triggers an event to reset the settings. If there is something like that you are looking for please let me know :)
@jeffpaul jeffpaul added this to the 1.7.0 milestone Jan 27, 2021
Copy link
Contributor

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks good. But I think we can go one step further. The settings are in two places which is a code smell to me. What do you think about creating a function that returns the default settings, then using that function in your function and setup_fields_sections?

Created a get_default_settings() method that returns the default settings, then used that function in reset_settings() method and setup_fields_sections() method
@ActuallyConnor
Copy link
Contributor Author

Hey @dinhtungdu I created a get_default_settings() method that returns the default settings, then used that function in reset_settings() method and setup_fields_sections() method as you requested. Let me know what you think 😄

Copy link
Contributor

@dinhtungdu dinhtungdu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ActuallyConnor, thanks for the update. I still have some questions, can you please take another look?

@@ -603,16 +623,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() );
$settings = $this->get_default_settings();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can be more explicit here, $default_settings sounds better to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I can implement this request.

Comment on lines 710 to 753
add_settings_field(
'caption-threshold',
esc_html__( 'Caption Confidence Threshold', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'caption_threshold',
'input_type' => 'number',
'default_value' => $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' ),
]
);
add_settings_field(
'image-tag-threshold',
esc_html__( 'Tag Confidence Threshold', 'classifai' ),
[ $this, 'render_input' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'tag_threshold',
'input_type' => 'number',
'default_value' => $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 = [];
foreach ( $attachment_taxonomies as $name => $taxonomy ) {
$options[ $name ] = $taxonomy->label;
}
add_settings_field(
'image-tag-taxonomy',
esc_html__( 'Tag Taxonomy', 'classifai' ),
[ $this, 'render_select' ],
$this->get_option_name(),
$this->get_option_name(),
[
'label_for' => 'image_tag_taxonomy',
'options' => $options,
'default_value' => $settings['image_tag_taxonomy'],
]
);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you explain why we should move this code here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I decided to reorder the settings fields in the function to match the order that appears in the default settings array. I ordered the default settings array based on the order that was returned in the database when I created a fresh install of the plugin.

I think it's best if the settings field order matches the order of the default settings field array, but I am not married to the current order of things (as I said, I just copied the order based on the serialized array that was returned in the database).

In my opinion we have two routes to choose from:

  1. Keep it as is since the settings fields order matches the default settings array order which matches the order of the serialized array.
  2. Revert the settings fields order back to the way it was, then match the default settings array order to the original settings fields order (this would just mean that we would ignore the database serialized array settings order which is fine as well since no one will really be looking at the database serialized array settings order).

Let me know what you would prefer, I am fine with going either route.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ActuallyConnor, I'm sorry for this very late reply. I think we should keep the order of fields as they were before. The order of fields in an associated array doesn't affect the way we're using it. And by keeping the order of settings fields, our users won't be surprised after updating the plugin. Do you want to continue working on this one (and updating the default setting variable name)? If not, please let me know, I can handle the rest.

@jeffpaul jeffpaul merged commit b30effe into 10up:develop May 7, 2021
@jeffpaul jeffpaul mentioned this pull request Aug 26, 2021
9 tasks
@jeffpaul jeffpaul linked an issue Dec 9, 2021 that may be closed by this pull request
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do the TODOs
3 participants