diff --git a/class-two-factor-core.php b/class-two-factor-core.php index 6a990c87..c033e904 100644 --- a/class-two-factor-core.php +++ b/class-two-factor-core.php @@ -179,17 +179,27 @@ public static function get_providers() { /** * For each filtered provider, */ - foreach ( $providers as $class => $path ) { + foreach ( $providers as $provider_key => $path ) { include_once $path; + $class = $provider_key; + + /** + * Filters the classname for a provider. The dynamic portion of the filter is the defined providers key. + * + * @param string $class The PHP Classname of the provider. + * @param string $path The provided provider path to be included. + */ + $class = apply_filters( "two_factor_provider_classname_{$provider_key}", $class, $path ); + /** * Confirm that it's been successfully included before instantiating. */ if ( class_exists( $class ) ) { try { - $providers[ $class ] = call_user_func( array( $class, 'get_instance' ) ); + $providers[ $provider_key ] = call_user_func( array( $class, 'get_instance' ) ); } catch ( Exception $e ) { - unset( $providers[ $class ] ); + unset( $providers[ $provider_key ] ); } } } @@ -411,9 +421,9 @@ public static function get_available_providers_for_user( $user = null ) { $enabled_providers = self::get_enabled_providers_for_user( $user ); $configured_providers = array(); - foreach ( $providers as $classname => $provider ) { - if ( in_array( $classname, $enabled_providers, true ) && $provider->is_available_for_user( $user ) ) { - $configured_providers[ $classname ] = $provider; + foreach ( $providers as $provider_key => $provider ) { + if ( in_array( $provider_key, $enabled_providers, true ) && $provider->is_available_for_user( $user ) ) { + $configured_providers[ $provider_key ] = $provider; } } @@ -712,10 +722,9 @@ public static function login_html( $user, $login_nonce, $redirect_to, $error_msg $provider = call_user_func( array( $provider, 'get_instance' ) ); } - $provider_class = get_class( $provider ); - + $provider_key = $provider->get_key(); $available_providers = self::get_available_providers_for_user( $user ); - $backup_providers = array_diff_key( $available_providers, array( $provider_class => null ) ); + $backup_providers = array_diff_key( $available_providers, array( $provider_key => null ) ); $interim_login = isset( $_REQUEST['interim-login'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended $rememberme = intval( self::rememberme() ); @@ -735,7 +744,7 @@ public static function login_html( $user, $login_nonce, $redirect_to, $error_msg ?>