Skip to content

Commit

Permalink
Only the uninstall logic should care about disabled providers
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Dec 2, 2024
1 parent fc771fb commit 93f561f
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions class-two-factor-core.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,22 @@ public static function uninstall() {

$option_keys = array();

foreach ( self::get_providers_classes() as $provider_class ) {
$providers = self::get_default_providers();

/**
* Include additional providers to be uninstalled.
*
* @param array $providers A key-value array where the key is the class name, and
* the value is the path to the file containing the class.
*/
$additional_providers = apply_filters( 'two_factor_providers', $providers );

// Merge them with the default providers.
if ( ! empty( $additional_providers ) ) {
return array_merge( $providers, $additional_providers );
}

foreach ( self::get_providers_classes( $providers ) as $provider_class ) {
// Merge with provider-specific user meta keys.
if ( method_exists( $provider_class, 'uninstall_user_meta_keys' ) ) {
try {
Expand Down Expand Up @@ -192,29 +207,14 @@ public static function uninstall() {
*
* @return array List of provider keys and paths to class files.
*/
public static function get_providers_registered() {
$providers = array(
private static function get_default_providers() {
return array(
'Two_Factor_Email' => TWO_FACTOR_DIR . 'providers/class-two-factor-email.php',
'Two_Factor_Totp' => TWO_FACTOR_DIR . 'providers/class-two-factor-totp.php',
'Two_Factor_FIDO_U2F' => TWO_FACTOR_DIR . 'providers/class-two-factor-fido-u2f.php',
'Two_Factor_Backup_Codes' => TWO_FACTOR_DIR . 'providers/class-two-factor-backup-codes.php',
'Two_Factor_Dummy' => TWO_FACTOR_DIR . 'providers/class-two-factor-dummy.php',
);

/**
* Filter the supplied providers.
*
* @param array $providers A key-value array where the key is the class name, and
* the value is the path to the file containing the class.
*/
$additional_providers = apply_filters( 'two_factor_providers', $providers );

// Merge them with the default providers.
if ( ! empty( $additional_providers ) ) {
return array_merge( $providers, $additional_providers );
}

return $providers;
}

/**
Expand Down Expand Up @@ -261,7 +261,7 @@ private static function get_providers_classes( $providers ) {
* @return array
*/
public static function get_providers() {
$providers = self::get_providers_registered();
$providers = self::get_default_providers();

/**
* Filter the supplied providers.
Expand Down

0 comments on commit 93f561f

Please sign in to comment.