Skip to content

Commit

Permalink
Account for options too
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Sep 18, 2024
1 parent 6f50ece commit 5d3b529
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ public static function uninstall() {
self::USER_PASSWORD_WAS_RESET_KEY,
);

// Merge with any provider-specific user meta keys.
$option_keys = array();

foreach ( self::get_providers_classes() as $provider_class ) {
// Merge with provider-specific user meta keys.
if ( method_exists( $provider_class, 'uninstall_user_meta_keys' ) ) {
try {
$user_meta_keys = array_merge(
Expand All @@ -159,8 +161,32 @@ public static function uninstall() {
// Do nothing.
}
}

// Merge with provider-specific option keys.
if ( method_exists( $provider_class, 'uninstall_options' ) ) {
try {
$option_keys = array_merge(
$option_keys,
call_user_func( array( $provider_class, 'uninstall_options' ) )
);
} catch ( Exception $e ) {
// Do nothing.
}
}
}

// Delete options first since that is faster.
if ( ! empty( $option_keys ) ) {
foreach ( $option_keys as $option_key ) {
delete_option( $option_key );
}
}

/**
* Get all user IDs to delete their user meta.
*
* Consider replacing this with a direct SQL query to speed up the process.
*/
$user_ids = get_users(
array(
'blog_id' => 0, // Return all users.
Expand Down

0 comments on commit 5d3b529

Please sign in to comment.