>, frequency: string, force_frequency: bool, delete_on_uninstall: bool} */ public function get_settings(): array { $settings_page = new Settings_Page(); return $settings_page->get_settings(); } /** * Retrieve the per-role method map. * * @return array> */ public function get_role_methods(): array { return $this->get_settings()['role_methods']; } /** * Retrieve the list of roles that have at least one required method configured. * * @return array */ public function get_forced_roles(): array { return array_keys( $this->get_role_methods() ); } /** * Retrieve the required verification methods for a specific role. * * @param string $role Role slug. * * @return array */ public function get_methods_for_role( string $role ): array { $role_methods = $this->get_role_methods(); return $role_methods[ $role ] ?? array(); } /** * Retrieve the union of required methods across all of a user's roles. * * Returns an empty array when none of the user's roles have required methods. * * @param \WP_User $user User object currently being authenticated. * * @return array */ public function get_required_methods_for_user( \WP_User $user ): array { $role_methods = $this->get_role_methods(); $required = array(); foreach ( $user->roles as $role ) { if ( isset( $role_methods[ $role ] ) ) { foreach ( $role_methods[ $role ] as $method ) { $required[] = $method; } } } return array_values( array_unique( $required ) ); } /** * Determine if two-factor authentication is enforced for the provided user. * * @param \WP_User $user User object currently being authenticated. * * @return bool */ public function is_two_factor_forced_for_user( \WP_User $user ): bool { return ! empty( $this->get_required_methods_for_user( $user ) ); } /** * Retrieve the globally configured verification frequency. * * @return string */ public function get_frequency(): string { return $this->get_settings()['frequency']; } /** * Determine whether the global frequency must be enforced for all users. * * @return bool */ public function is_frequency_forced(): bool { return $this->get_settings()['force_frequency']; } }