Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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();

Expand Down
4 changes: 2 additions & 2 deletions settings/class-two-factor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<div class="updated"><p>' . esc_html__( 'Settings saved.', 'two-factor' ) . '</p></div>';
}
Expand All @@ -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 '<div class="wrap two-factor-settings">';
echo '<h1>' . esc_html__( 'Two-Factor Settings', 'two-factor' ) . '</h1>';
Expand Down
22 changes: 22 additions & 0 deletions tests/class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion two-factor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down
Loading