From 58e30e0ba5447dbba014df54429bfcd4326370d6 Mon Sep 17 00:00:00 2001 From: Kaspars Dambis Date: Fri, 14 Feb 2025 16:59:11 +0200 Subject: [PATCH] Add a helper to check if the method is supported for the user --- providers/class-two-factor-provider.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/providers/class-two-factor-provider.php b/providers/class-two-factor-provider.php index 0e82dd67..6f494c3d 100644 --- a/providers/class-two-factor-provider.php +++ b/providers/class-two-factor-provider.php @@ -123,6 +123,19 @@ abstract public function validate_authentication( $user ); */ abstract public function is_available_for_user( $user ); + /** + * If this provider should be available for the user. + * + * @param WP_User|int $user WP_User object, user ID or null to resolve the current user. + * + * @return bool + */ + public static function is_supported_for_user( $user = null ) { + $providers = Two_Factor_Core::get_supported_providers_for_user( $user ); + + return isset( $providers[ self::class ] ); + } + /** * Generate a random eight-digit string to send out as an auth code. *