Skip to content

fix(uninstall): remove two_factor_enabled_providers option on uninstall#903

Open
faisalahammad wants to merge 1 commit into
WordPress:masterfrom
faisalahammad:fix/902-uninstall-option-cleanup
Open

fix(uninstall): remove two_factor_enabled_providers option on uninstall#903
faisalahammad wants to merge 1 commit into
WordPress:masterfrom
faisalahammad:fix/902-uninstall-option-cleanup

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jun 11, 2026

Copy link
Copy Markdown

Summary

The two_factor_enabled_providers option (added in 0.16) was not being removed when the plugin is uninstalled, leaving an orphaned row in wp_options. This fix adds the option to the uninstall list and centralises the key in a class constant.

Fixes #902

Changes

class-two-factor-core.php

Before:

$option_keys = array();

After:

const ENABLED_PROVIDERS_OPTION_KEY = 'two_factor_enabled_providers';

// ...

// Keep this updated as plugin-level options are added or removed.
$option_keys = array(
    self::ENABLED_PROVIDERS_OPTION_KEY,
);

Why: Mirrors the existing pattern of constants-on-the-class for every other plugin meta/option key and adds the missing option to the uninstall list.

two-factor.php and settings/class-two-factor-settings.php

Replaced the literal 'two_factor_enabled_providers' with Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY so the key lives in one place.

tests/class-two-factor-core.php

Added test_uninstall_removes_enabled_providers_option to cover the new cleanup path.

Testing

Test 1: Automated

  1. npm test
  2. Filter to uninstall: npm run composer -- test -- --filter test_uninstall

Result: 185/185 pass (6 uninstall tests pass, including the new one).

Test 2: Manual

  1. WP Admin → Settings → Two-Factor, save a non-default provider set.
  2. WP Admin → Plugins → Deactivate then Delete "Two Factor".
  3. Inspect wp_options: no two_factor_enabled_providers row.
  4. Reinstall the plugin: settings page loads, "never saved" default applies.

@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: faisalahammad <faisalahammad@git.wordpress.org>
Co-authored-by: kasparsd <kasparsd@git.wordpress.org>
Co-authored-by: masteradhoc <masteradhoc@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@kasparsd kasparsd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice, looks great!

Comment thread TESTING_INSTRUCTIONS.md Outdated
The site-wide enabled providers option added in 0.16 was not
included in Two_Factor_Core::uninstall(), so it was left behind
in wp_options after uninstalling the plugin.

Add a class constant for the option key and include it in the
uninstall list. Replace the literal in the main file and settings
UI to use the constant.

Fixes WordPress#902
@faisalahammad faisalahammad force-pushed the fix/902-uninstall-option-cleanup branch from 179704f to 60628e8 Compare June 11, 2026 18:48
@faisalahammad

faisalahammad commented Jun 11, 2026

Copy link
Copy Markdown
Author

Done. Removed TESTING_INSTRUCTIONS.md from the PR (was a manual testing artifact left in the tree by mistake). Amended onto the existing commit, force-pushed to fix/902-uninstall-option-cleanup.

Diff: https://github.com/WordPress/two-factor/pull/903/files

@faisalahammad faisalahammad requested a review from kasparsd June 11, 2026 18:49
@masteradhoc masteradhoc added this to the 0.17.0 milestone Jun 12, 2026
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.

Bug: Plugin does not remove all data from the database on uninstall

3 participants