Skip to content

Commit

Permalink
add cleanup logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Sidsector9 committed Jul 19, 2022
1 parent a663cad commit c31307d
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions sophi.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,45 @@ function() {
}
);

add_action(
'plugin_loaded',
function( $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 );
}
}
);

/**
* Sophi HTTPS notice.
*/
Expand Down

0 comments on commit c31307d

Please sign in to comment.