Skip to content

Support filtering providers per user#648

Closed
ocean90 wants to merge 1 commit intoWordPress:masterfrom
wearerequired:feature/provider-per-user
Closed

Support filtering providers per user#648
ocean90 wants to merge 1 commit intoWordPress:masterfrom
wearerequired:feature/provider-per-user

Conversation

@ocean90
Copy link
Copy Markdown
Member

@ocean90 ocean90 commented Nov 6, 2024

What?

Pass the current user to get_providers() and its filter.

Why?

Fixes #647.

How?

Update all get_providers() calls and the filter to support the new $user_id argument.

Testing Instructions

Use the following code to allow email and TOTP for the user with ID 1 and email for other users.

add_filter(
	'two_factor_providers',
	static function ( array $providers, ?int $user_id ): array {
		if ( 1 === $user_id ) {
			return array_intersect_key(
				$providers,
				[
					'Two_Factor_Email' => '',
					'Two_Factor_Totp'  => '',
				]
			);
		} else {
			return array_intersect_key(
				$providers,
				[
					'Two_Factor_Email' => '',
				]
			);
		}
	},
	10,
	2
);

Screenshots or screencast

Changelog Entry

Added - Allow to filter providers per user.

@ocean90
Copy link
Copy Markdown
Member Author

ocean90 commented Nov 6, 2024

Pending feedback regards the two_factor_providers filter: #637 (comment)

@jeffpaul jeffpaul added this to the 0.10.0 milestone Nov 12, 2024
@jeffpaul jeffpaul requested a review from kasparsd November 12, 2024 19:53
@kasparsd
Copy link
Copy Markdown
Collaborator

Created #669 to resolve the conflicts. Please review that for the suggested implementation.

@kasparsd kasparsd closed this Feb 14, 2025
@jeffpaul jeffpaul removed this from the 0.14.0 milestone Apr 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow to limit providers per user

3 participants