Standardise on int|WP_User
input to the "for user" functions
#535
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently the various API-level functions accept two main inputs:
ID
orWP_User
, and assumes that if not provided the function should operate on the current user.Accepts
WP_User
:Two_Factor_Core::get_enabled_providers_for_user()
Two_Factor_Core::get_available_providers_for_user()
Accepts
ID
:Two_Factor_Core::get_primary_provider_for_user()
Two_Factor_Core::is_user_using_two_factor()
When a WP_User is passed in place of an ID, or an ID in place of a WP_User, the functions operate on the current user, which could lead to unexpected responses.
This PR standardises the above 4 functions to:
int|WP_User
null
is passed (The default value for the function param)For example, currently:
After this PR, both
$incorrect
and$correct
in the above would contain the details for user 2.I'll note that
is_user_api_login_enabled()
has not been touched, as the$user_id
is not used for any logic within the function, and the onus is on the filtering functions to check the value of$user_id
passed.