user_storage = $user_storage; $this->options_storage = $options_storage; } /** * @deprecated * * @return bool * * @throws User_Not_Found_Exception */ public function totp_is_obligatory_or_legacy_mode_is_active() { return $this->options_storage->has_twofas_role( $this->user_storage->get_roles() ) || $this->is_2fa_enabled_in_legacy_mode(); } /** * @deprecated * * @return bool * * @throws User_Not_Found_Exception */ public function totp_is_obligatory_and_legacy_mode_is_active() { return $this->options_storage->has_twofas_role( $this->user_storage->get_roles() ) && $this->is_2fa_enabled_in_legacy_mode(); } /** * @deprecated * * @return bool * * @throws User_Not_Found_Exception */ public function totp_is_obligatory_and_legacy_mode_is_not_active() { return $this->options_storage->has_twofas_role( $this->user_storage->get_roles() ) && ! $this->is_2fa_enabled_in_legacy_mode(); } /** * @deprecated * * @return bool * * @throws User_Not_Found_Exception */ public function is_2fa_enabled_in_legacy_mode() { return ! $this->user_storage->is_totp_enabled() && $this->user_storage->is_2fa_enabled(); } /** * @deprecated */ public function disable_legacy_2fa() { $users = $this->get_users_in_legacy_mode(); foreach ( $users as $user ) { $this->set_user_meta( $user->ID, User_Storage::SECOND_FACTOR_STATUS, User_Storage::TWO_FACTOR_AUTH_DISABLED ); } } /** * @return WP_User[] */ private function get_users_in_legacy_mode() { $users = $this->get_users_with_enabled_two_factor_authentication(); $users_in_legacy_mode = array(); foreach ( $users as $user ) { $totp_status = get_user_meta( $user->ID, User_Storage::TOTP_STATUS, true ); if ( User_Storage::METHOD_CONFIGURED_ENABLED !== $totp_status ) { $users_in_legacy_mode[] = $user; } } return $users_in_legacy_mode; } /** * @return WP_User[] */ private function get_users_with_enabled_two_factor_authentication() { return get_users( array( 'meta_key' => User_Storage::SECOND_FACTOR_STATUS, 'meta_value' => '1', ) ); } /** * @param int $user_id * @param string $meta_key * @param array|int|string $meta_value */ private function set_user_meta( $user_id, $meta_key, $meta_value ) { update_user_meta( $user_id, $meta_key, $meta_value ); } }