-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat/603: remove Auth0 related features #310
Conversation
delete_option( 'sophi_site_automation_access_token' ); | ||
} | ||
|
||
if ( ! empty( $settings['client_id'] && ! empty( $settings['client_secret'] ) ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we may still want some validation that Host/Tenant ID are entered when someone tries to save the form.
sophi.php
Outdated
function sophi_remove_stale_data( $plugin ) { | ||
/** Return if the plugin is not Sophi. */ | ||
if ( 'sophi.php' !== basename( $plugin ) ) { | ||
return; | ||
} | ||
|
||
$version_key = 'sophi_version'; | ||
$current_version = get_transient( $version_key ); | ||
|
||
if ( false === $current_version ) { | ||
$current_version = get_option( $version_key, false ); | ||
|
||
if ( false !== $current_version ) { | ||
set_transient( $version_key, $current_version ); | ||
} | ||
} | ||
|
||
if ( SOPHI_WP_VERSION === $current_version ) { | ||
return; | ||
} | ||
|
||
if ( false === $current_version || version_compare( $current_version, SOPHI_WP_VERSION, '<' ) ) { | ||
|
||
/** Cleanup logic before setting the new version of the plugin. */ | ||
delete_option( 'sophi_site_automation_access_token' ); | ||
|
||
$sophi_settings = get_option( 'sophi_settings' ); | ||
unset( $sophi_settings['client_id'] ); | ||
unset( $sophi_settings['client_secret'] ); | ||
|
||
update_option( 'sophi_settings', $sophi_settings ); | ||
update_option( $version_key, SOPHI_WP_VERSION, true ); | ||
set_transient( $version_key, SOPHI_WP_VERSION ); | ||
} | ||
} | ||
|
||
add_action( 'plugin_loaded', 'sophi_remove_stale_data' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit worried about the new option in terms of site performance. Is there another way to clean the data without adding a new option?
I think we can remove irrelevant options when updating the Sophi setting. Do you think it's sufficient to clean the old settings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dinhtungdu I've replaced this logic, can you check?
223b11b
to
78e8488
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Sidsector9 thanks for the update! I just have one more minor comment, otherwise, this is LGTM!
sophi.php
Outdated
/** | ||
* Method to cleanup settings before setting the new version. | ||
* | ||
* @param mixed $value The new, unserialized option value. | ||
* | ||
* @return mixed | ||
*/ | ||
function sophi_remove_stale_data( $value ) { | ||
$is_client_id_set = isset( $value['client_id'] ); | ||
$is_client_secret_set = isset( $value['client_secret'] ); | ||
|
||
if ( ! $is_client_id_set && ! $is_client_secret_set ) { | ||
return $value; | ||
} | ||
|
||
if ( $is_client_id_set ) { | ||
unset( $value['client_id'] ); | ||
} | ||
|
||
if ( isset( $is_client_secret_set ) ) { | ||
unset( $value['client_secret'] ); | ||
} | ||
|
||
return $value; | ||
} | ||
add_filter( 'pre_update_option_sophi_settings', 'sophi_remove_stale_data' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic can be added to the sanitize_settings
function in includes/functions/settings.php
instead.
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
@Sidsector9 Thanks so much for being patient with me! This is LGTM now! |
Description of the Change
Closes #306
Checklist:
Changelog Entry
Credits
Props @Sidsector9