/** * Gets the Two-Factor Auth provider for the specified|current user. * * @param int $user_id Optional. User ID. Default is 'null'. * @return object|null */ public function get_primary_provider_for_user( $user_id = null ) { if ( empty( $user_id ) || ! is_numeric( $user_id ) ) { $user_id = get_current_user_id(); } $providers = $this->_helper->get_enabled_provider_instances(); $available_providers = $this->get_available_providers_for_user( get_userdata( $user_id ) ); // If there's only one available provider, force that to be the primary. if ( empty( $available_providers ) ) { return null; } elseif ( 1 === count( $available_providers ) ) { $provider = key( $available_providers ); } else { $provider = get_user_meta( $user_id, $this->_provider_user_meta_key, true ); // If the provider specified isn't enabled, just grab the first one that is. if ( ! isset( $available_providers[ $provider ] ) ) { $provider = key( $available_providers ); } } /** * Filter the two-factor authentication provider used for this user. * * @param string $provider The provider currently being used. * @param int $user_id The user ID. */ $provider = apply_filters( 'two_factor_primary_provider_for_user', $provider, $user_id ); if ( isset( $providers[ $provider ] ) ) { return $providers[ $provider ]; } return null; }