Skip to content

Instantly share code, notes, and snippets.

@pdewouters
Created November 15, 2022 15:47
Show Gist options
  • Save pdewouters/c500d010b2753a8b37a7a62a0b95ea9d to your computer and use it in GitHub Desktop.
Save pdewouters/c500d010b2753a8b37a7a62a0b95ea9d to your computer and use it in GitHub Desktop.
vipps phone login
add_filter( 'login_with_vipps_authenticate_user', [ $this, 'maybe_auth_winorg_phone' ], 10, 3 );
public function maybe_auth_winorg_phone( $user, array $userinfo, \VippsSession $session ) {
if ( $user instanceof \WP_User ) {
return $user;
}
// phpcs:enable NeutronStandard.Functions.TypeHint.NoArgumentType, NeutronStandard.Functions.TypeHint.NoReturnType
$args = [
'meta_query' => [ // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_query
[
'key' => 'Phone',
'value' => substr( $userinfo['phone_number'], 2 ),
'compare' => '=',
],
],
];
$users = get_users( $args );
return ! empty( $users ) && ( $users[0] instanceof \WP_User ) ? $users[0] : $user;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment