diff --git a/class-two-factor-core.php b/class-two-factor-core.php
index d98cbfe6..81d6aa4c 100644
--- a/class-two-factor-core.php
+++ b/class-two-factor-core.php
@@ -28,6 +28,15 @@ class Two_Factor_Core {
*/
const ENABLED_PROVIDERS_USER_META_KEY = '_two_factor_enabled_providers';
+ /**
+ * The site-wide enabled providers option key.
+ *
+ * @since 0.16.1
+ *
+ * @type string
+ */
+ const ENABLED_PROVIDERS_OPTION_KEY = 'two_factor_enabled_providers';
+
/**
* The user meta nonce key.
*
@@ -189,7 +198,10 @@ public static function uninstall() {
self::USER_PASSWORD_WAS_RESET_KEY,
);
- $option_keys = array();
+ // Keep this updated as plugin-level options are added or removed.
+ $option_keys = array(
+ self::ENABLED_PROVIDERS_OPTION_KEY,
+ );
$providers = self::get_default_providers();
diff --git a/settings/class-two-factor-settings.php b/settings/class-two-factor-settings.php
index 48018835..9e7fa886 100644
--- a/settings/class-two-factor-settings.php
+++ b/settings/class-two-factor-settings.php
@@ -39,7 +39,7 @@ public static function render_settings_page() {
// Remove empty values.
$enabled = array_values( array_filter( $posted, 'strlen' ) );
- update_option( 'two_factor_enabled_providers', array_values( array_unique( $enabled ) ) );
+ update_option( Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY, array_values( array_unique( $enabled ) ) );
echo '
' . esc_html__( 'Settings saved.', 'two-factor' ) . '
';
}
@@ -55,7 +55,7 @@ public static function render_settings_page() {
// Default to all providers enabled when the option has never been saved.
$all_provider_keys = array_keys( $provider_instances );
- $saved_enabled = get_option( 'two_factor_enabled_providers', $all_provider_keys );
+ $saved_enabled = get_option( Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY, $all_provider_keys );
echo '';
echo '
' . esc_html__( 'Two-Factor Settings', 'two-factor' ) . '
';
diff --git a/tests/class-two-factor-core.php b/tests/class-two-factor-core.php
index c265f6aa..40467b6a 100644
--- a/tests/class-two-factor-core.php
+++ b/tests/class-two-factor-core.php
@@ -1890,6 +1890,28 @@ function ( $providers ) {
remove_all_filters( 'two_factor_providers' );
}
+ /**
+ * Plugin uninstall removes the site-wide enabled providers option.
+ *
+ * @covers Two_Factor_Core::uninstall
+ */
+ public function test_uninstall_removes_enabled_providers_option() {
+ update_option( Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY, array( 'Two_Factor_Email' ) );
+
+ $this->assertSame(
+ array( 'Two_Factor_Email' ),
+ get_option( Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY ),
+ 'Enabled providers option was set'
+ );
+
+ Two_Factor_Core::uninstall();
+
+ $this->assertFalse(
+ get_option( Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY ),
+ 'Enabled providers option was deleted during uninstall'
+ );
+ }
+
/**
* Test delete_login_nonce removes the nonce.
*
diff --git a/two-factor.php b/two-factor.php
index d1cc2413..b1db2039 100644
--- a/two-factor.php
+++ b/two-factor.php
@@ -129,7 +129,7 @@ function two_factor_render_settings_page() {
* @return array|null
*/
function two_factor_get_enabled_providers_option() {
- $enabled = get_option( 'two_factor_enabled_providers', null );
+ $enabled = get_option( Two_Factor_Core::ENABLED_PROVIDERS_OPTION_KEY, null );
if ( null === $enabled ) {
return null; // Never saved — allow everything.
}