This commit is contained in:
Javier Casares 2026-06-06 05:08:20 +00:00
commit 054060374e
9 changed files with 4058 additions and 73 deletions

View file

@ -8,6 +8,8 @@
namespace Robotstxt\TwoFA\Admin;
use Robotstxt\TwoFA\Attempts_Log;
use Robotstxt\TwoFA\User\Two_Factor_Config;
use Robotstxt\TwoFA\User\User_Settings_Repository;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@ -29,13 +31,39 @@ class Dashboard_Page {
*/
private Attempts_Log $attempts_log;
/**
* Global two-factor configuration.
*
* @var Two_Factor_Config
*/
private Two_Factor_Config $config;
/**
* User settings repository.
*
* @var User_Settings_Repository
*/
private User_Settings_Repository $repository;
/**
* Users list table.
*
* @var Users_List_Table
*/
private Users_List_Table $users_table;
/**
* Constructor.
*
* @param Attempts_Log $attempts_log Failed attempts log instance.
* @param Attempts_Log $attempts_log Failed attempts log instance.
* @param Two_Factor_Config $config Global two-factor configuration.
* @param User_Settings_Repository $repository User settings repository.
*/
public function __construct( Attempts_Log $attempts_log ) {
public function __construct( Attempts_Log $attempts_log, Two_Factor_Config $config, User_Settings_Repository $repository ) {
$this->attempts_log = $attempts_log;
$this->config = $config;
$this->repository = $repository;
$this->users_table = new Users_List_Table( $config, $repository );
}
/**
@ -49,6 +77,7 @@ class Dashboard_Page {
add_action( 'admin_menu', array( $this, 'register_menu' ) );
add_filter( 'manage_users_columns', array( $this, 'add_users_column' ) );
add_filter( 'manage_users_custom_column', array( $this, 'render_users_column' ), 10, 3 );
add_action( 'admin_post_robotstxt_2fa_export_users', array( $this, 'handle_csv_export' ) );
}
/**
@ -136,6 +165,22 @@ class Dashboard_Page {
</div>
</div>
<h2><?php esc_html_e( 'Users', 'robotstxt-2fa' ); ?></h2>
<form method="get">
<input type="hidden" name="page" value="<?php echo esc_attr( self::PAGE_SLUG ); ?>" />
<?php
$this->users_table->prepare_items();
$this->users_table->display();
?>
</form>
<form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>" style="margin-top:1em;">
<input type="hidden" name="action" value="robotstxt_2fa_export_users" />
<?php wp_nonce_field( 'robotstxt_2fa_export_users' ); ?>
<?php submit_button( __( 'Export CSV', 'robotstxt-2fa' ), 'secondary', 'submit', false ); ?>
</form>
<h2><?php esc_html_e( 'Recent failed attempts', 'robotstxt-2fa' ); ?></h2>
<?php if ( empty( $recent_attempts ) ) : ?>
@ -170,6 +215,100 @@ class Dashboard_Page {
<?php
}
/**
* Handle the CSV export admin-post action.
*
* @since 1.5.0
*
* @return void
*/
public function handle_csv_export(): void {
check_admin_referer( 'robotstxt_2fa_export_users' );
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'Sorry, you are not allowed to access this page.', 'robotstxt-2fa' ) );
}
$users = get_users(
array(
'number' => -1,
'fields' => 'all',
)
);
$rows = array();
foreach ( $users as $user ) {
if ( ! $user instanceof \WP_User ) {
continue;
}
$settings = $this->repository->get_user_settings( $user->ID );
$is_enabled = $settings['enabled'];
$required_methods = $this->config->get_required_methods_for_user( $user );
$is_forced = ! empty( $required_methods );
if ( $is_enabled ) {
$status = 'active';
} elseif ( $is_forced ) {
$status = 'required';
} else {
$status = 'optional';
}
$last_verified_ts = 0;
$raw_verifications = get_user_meta( $user->ID, 'robotstxt_2fa_last_verifications', true );
if ( is_array( $raw_verifications ) ) {
foreach ( $raw_verifications as $method_data ) {
if ( is_array( $method_data ) ) {
foreach ( $method_data as $context_data ) {
if ( is_array( $context_data ) && isset( $context_data['verified_at'] ) && is_int( $context_data['verified_at'] ) ) {
$last_verified_ts = max( $last_verified_ts, $context_data['verified_at'] );
}
}
}
}
}
$last_verified_str = $last_verified_ts > 0 ? (string) wp_date( 'Y-m-d H:i', $last_verified_ts ) : '';
$unused_codes = 0;
$raw_codes = get_user_meta( $user->ID, 'robotstxt_2fa_recovery_codes', true );
if ( is_array( $raw_codes ) && isset( $raw_codes['codes'] ) && is_array( $raw_codes['codes'] ) ) {
foreach ( $raw_codes['codes'] as $code_entry ) {
if ( is_array( $code_entry ) && empty( $code_entry['used_at'] ) ) {
++$unused_codes;
}
}
}
$rows[] = array(
'ID' => (string) $user->ID,
'user_login' => $user->user_login,
'user_email' => $user->user_email,
'roles' => implode( '|', $user->roles ),
'status' => $status,
'methods' => implode( '|', $settings['methods'] ),
'last_verified' => $last_verified_str,
'unused_codes' => (string) $unused_codes,
);
}
header( 'Content-Type: text/csv' );
header( 'Content-Disposition: attachment; filename="2fa-users-' . gmdate( 'Y-m-d' ) . '.csv"' );
$headers = array( 'ID', 'Login', 'Email', 'Roles', 'Status', 'Methods', 'Last Verified', 'Unused Codes' );
echo implode( ',', array_map( 'addslashes', $headers ) ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- CSV output to a file download.
foreach ( $rows as $row ) {
echo implode( ',', array_map( 'addslashes', array_values( $row ) ) ) . "\n"; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- CSV output to a file download.
}
exit;
}
/**
* Add a 2FA status column to the users list table.
*

View file

@ -247,6 +247,14 @@ class Settings_Page {
'robotstxt_2fa_access'
);
add_settings_field(
'robotstxt_2fa_app_passwords_require_2fa_creation',
__( 'Require 2FA to create Application Passwords', 'robotstxt-2fa' ),
array( $this, 'render_app_passwords_require_2fa_creation_field' ),
self::PAGE_SLUG,
'robotstxt_2fa_access'
);
add_settings_field(
'robotstxt_2fa_ip_allow',
__( 'IP allow list', 'robotstxt-2fa' ),
@ -301,6 +309,45 @@ class Settings_Page {
self::PAGE_SLUG,
'robotstxt_2fa_notifications'
);
add_settings_section(
'robotstxt_2fa_geoip',
__( 'GeoIP / Country restrictions', 'robotstxt-2fa' ),
array( $this, 'render_geoip_section' ),
self::PAGE_SLUG
);
add_settings_field(
'robotstxt_2fa_geoip_database_path',
__( 'Database path', 'robotstxt-2fa' ),
array( $this, 'render_geoip_database_path_field' ),
self::PAGE_SLUG,
'robotstxt_2fa_geoip'
);
add_settings_field(
'robotstxt_2fa_geoip_country_allow',
__( 'Country allow list (bypass 2FA)', 'robotstxt-2fa' ),
array( $this, 'render_geoip_country_allow_field' ),
self::PAGE_SLUG,
'robotstxt_2fa_geoip'
);
add_settings_field(
'robotstxt_2fa_geoip_country_deny',
__( 'Country deny list (block login)', 'robotstxt-2fa' ),
array( $this, 'render_geoip_country_deny_field' ),
self::PAGE_SLUG,
'robotstxt_2fa_geoip'
);
add_settings_field(
'robotstxt_2fa_geoip_always_challenge',
__( 'Always challenge countries', 'robotstxt-2fa' ),
array( $this, 'render_geoip_always_challenge_field' ),
self::PAGE_SLUG,
'robotstxt_2fa_geoip'
);
}
/**
@ -504,7 +551,7 @@ class Settings_Page {
*
* @param mixed $raw_settings Raw settings submitted by the user.
*
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}}
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}, app_passwords_require_2fa_creation: bool, geoip_database_path: string, geoip_country_allow: string, geoip_country_deny: string, geoip_always_challenge: string}
*/
public function sanitize_settings( $raw_settings ): array {
$capability = $this->get_required_capability();
@ -616,13 +663,33 @@ class Settings_Page {
'digest_frequency' => isset( $raw_notif['digest_frequency'] ) && 'monthly' === $raw_notif['digest_frequency'] ? 'monthly' : 'weekly',
);
if ( array_key_exists( 'app_passwords_require_2fa_creation', $raw_settings ) ) {
$sanitized['app_passwords_require_2fa_creation'] = '1' === ( is_scalar( $raw_settings['app_passwords_require_2fa_creation'] ) ? (string) $raw_settings['app_passwords_require_2fa_creation'] : '' );
}
if ( isset( $raw_settings['geoip_database_path'] ) && is_string( $raw_settings['geoip_database_path'] ) ) {
$sanitized['geoip_database_path'] = sanitize_text_field( $raw_settings['geoip_database_path'] );
}
if ( isset( $raw_settings['geoip_country_allow'] ) && is_string( $raw_settings['geoip_country_allow'] ) ) {
$sanitized['geoip_country_allow'] = strtoupper( sanitize_textarea_field( $raw_settings['geoip_country_allow'] ) );
}
if ( isset( $raw_settings['geoip_country_deny'] ) && is_string( $raw_settings['geoip_country_deny'] ) ) {
$sanitized['geoip_country_deny'] = strtoupper( sanitize_textarea_field( $raw_settings['geoip_country_deny'] ) );
}
if ( isset( $raw_settings['geoip_always_challenge'] ) && is_string( $raw_settings['geoip_always_challenge'] ) ) {
$sanitized['geoip_always_challenge'] = strtoupper( sanitize_textarea_field( $raw_settings['geoip_always_challenge'] ) );
}
return $sanitized;
}
/**
* Retrieve plugin settings, migrating from legacy format when necessary.
*
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}}
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}, app_passwords_require_2fa_creation: bool, geoip_database_path: string, geoip_country_allow: string, geoip_country_deny: string, geoip_always_challenge: string}
*/
public function get_settings(): array {
$options = array();
@ -647,19 +714,19 @@ class Settings_Page {
$def_notif = $defaults['notifications'];
return array(
'role_methods' => $this->resolve_role_methods( $options ),
'frequency' => Frequency_Options::sanitize( isset( $options['frequency'] ) && is_string( $options['frequency'] ) ? $options['frequency'] : '' ),
'force_frequency' => ! empty( $options['force_frequency'] ),
'delete_on_uninstall' => ! empty( $options['delete_on_uninstall'] ),
'max_attempts' => isset( $options['max_attempts'] ) && is_numeric( $options['max_attempts'] ) ? max( 0, absint( $options['max_attempts'] ) ) : $defaults['max_attempts'],
'lockout_duration' => isset( $options['lockout_duration'] ) && is_numeric( $options['lockout_duration'] ) ? max( 1, absint( $options['lockout_duration'] ) ) : $defaults['lockout_duration'],
'trust_device_days' => isset( $options['trust_device_days'] ) && is_numeric( $options['trust_device_days'] ) ? max( 0, absint( $options['trust_device_days'] ) ) : $defaults['trust_device_days'],
'grace_period_days' => isset( $options['grace_period_days'] ) && is_numeric( $options['grace_period_days'] ) ? max( 0, absint( $options['grace_period_days'] ) ) : $defaults['grace_period_days'],
'grace_period_action' => isset( $options['grace_period_action'] ) && in_array( $options['grace_period_action'], array( 'block', 'wizard' ), true ) ? $options['grace_period_action'] : $defaults['grace_period_action'],
'app_passwords_exempt' => isset( $options['app_passwords_exempt'] ) ? (bool) $options['app_passwords_exempt'] : $defaults['app_passwords_exempt'],
'ip_allow' => isset( $options['ip_allow'] ) && is_string( $options['ip_allow'] ) ? $options['ip_allow'] : $defaults['ip_allow'],
'ip_deny' => isset( $options['ip_deny'] ) && is_string( $options['ip_deny'] ) ? $options['ip_deny'] : $defaults['ip_deny'],
'notifications' => array(
'role_methods' => $this->resolve_role_methods( $options ),
'frequency' => Frequency_Options::sanitize( isset( $options['frequency'] ) && is_string( $options['frequency'] ) ? $options['frequency'] : '' ),
'force_frequency' => ! empty( $options['force_frequency'] ),
'delete_on_uninstall' => ! empty( $options['delete_on_uninstall'] ),
'max_attempts' => isset( $options['max_attempts'] ) && is_numeric( $options['max_attempts'] ) ? max( 0, absint( $options['max_attempts'] ) ) : $defaults['max_attempts'],
'lockout_duration' => isset( $options['lockout_duration'] ) && is_numeric( $options['lockout_duration'] ) ? max( 1, absint( $options['lockout_duration'] ) ) : $defaults['lockout_duration'],
'trust_device_days' => isset( $options['trust_device_days'] ) && is_numeric( $options['trust_device_days'] ) ? max( 0, absint( $options['trust_device_days'] ) ) : $defaults['trust_device_days'],
'grace_period_days' => isset( $options['grace_period_days'] ) && is_numeric( $options['grace_period_days'] ) ? max( 0, absint( $options['grace_period_days'] ) ) : $defaults['grace_period_days'],
'grace_period_action' => isset( $options['grace_period_action'] ) && in_array( $options['grace_period_action'], array( 'block', 'wizard' ), true ) ? $options['grace_period_action'] : $defaults['grace_period_action'],
'app_passwords_exempt' => isset( $options['app_passwords_exempt'] ) ? (bool) $options['app_passwords_exempt'] : $defaults['app_passwords_exempt'],
'ip_allow' => isset( $options['ip_allow'] ) && is_string( $options['ip_allow'] ) ? $options['ip_allow'] : $defaults['ip_allow'],
'ip_deny' => isset( $options['ip_deny'] ) && is_string( $options['ip_deny'] ) ? $options['ip_deny'] : $defaults['ip_deny'],
'notifications' => array(
'on_enable' => isset( $raw_notif['on_enable'] ) ? (bool) $raw_notif['on_enable'] : $def_notif['on_enable'],
'on_new_ip' => isset( $raw_notif['on_new_ip'] ) ? (bool) $raw_notif['on_new_ip'] : $def_notif['on_new_ip'],
'on_recovery_used' => isset( $raw_notif['on_recovery_used'] ) ? (bool) $raw_notif['on_recovery_used'] : $def_notif['on_recovery_used'],
@ -667,29 +734,34 @@ class Settings_Page {
'digest_enabled' => isset( $raw_notif['digest_enabled'] ) ? (bool) $raw_notif['digest_enabled'] : $def_notif['digest_enabled'],
'digest_frequency' => isset( $raw_notif['digest_frequency'] ) && 'monthly' === $raw_notif['digest_frequency'] ? 'monthly' : $def_notif['digest_frequency'],
),
'app_passwords_require_2fa_creation' => isset( $options['app_passwords_require_2fa_creation'] ) ? (bool) $options['app_passwords_require_2fa_creation'] : $defaults['app_passwords_require_2fa_creation'],
'geoip_database_path' => isset( $options['geoip_database_path'] ) && is_string( $options['geoip_database_path'] ) ? $options['geoip_database_path'] : $defaults['geoip_database_path'],
'geoip_country_allow' => isset( $options['geoip_country_allow'] ) && is_string( $options['geoip_country_allow'] ) ? $options['geoip_country_allow'] : $defaults['geoip_country_allow'],
'geoip_country_deny' => isset( $options['geoip_country_deny'] ) && is_string( $options['geoip_country_deny'] ) ? $options['geoip_country_deny'] : $defaults['geoip_country_deny'],
'geoip_always_challenge' => isset( $options['geoip_always_challenge'] ) && is_string( $options['geoip_always_challenge'] ) ? $options['geoip_always_challenge'] : $defaults['geoip_always_challenge'],
);
}
/**
* Retrieve default settings.
*
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}}
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}, app_passwords_require_2fa_creation: bool, geoip_database_path: string, geoip_country_allow: string, geoip_country_deny: string, geoip_always_challenge: string}
*/
private function get_default_settings(): array {
return array(
'role_methods' => array(),
'frequency' => Frequency_Options::FREQUENCY_SESSION,
'force_frequency' => false,
'delete_on_uninstall' => false,
'max_attempts' => 3,
'lockout_duration' => 15,
'trust_device_days' => 30,
'grace_period_days' => 7,
'grace_period_action' => 'wizard',
'app_passwords_exempt' => true,
'ip_allow' => '',
'ip_deny' => '',
'notifications' => array(
'role_methods' => array(),
'frequency' => Frequency_Options::FREQUENCY_SESSION,
'force_frequency' => false,
'delete_on_uninstall' => false,
'max_attempts' => 3,
'lockout_duration' => 15,
'trust_device_days' => 30,
'grace_period_days' => 7,
'grace_period_action' => 'wizard',
'app_passwords_exempt' => true,
'ip_allow' => '',
'ip_deny' => '',
'notifications' => array(
'on_enable' => false,
'on_new_ip' => false,
'on_recovery_used' => false,
@ -697,6 +769,11 @@ class Settings_Page {
'digest_enabled' => false,
'digest_frequency' => 'weekly',
),
'app_passwords_require_2fa_creation' => false,
'geoip_database_path' => '',
'geoip_country_allow' => '',
'geoip_country_deny' => '',
'geoip_always_challenge' => '',
);
}
@ -1257,6 +1334,107 @@ class Settings_Page {
echo '</fieldset>';
}
/**
* Render the Application Passwords require 2FA creation checkbox.
*
* @return void
*/
public function render_app_passwords_require_2fa_creation_field(): void {
$settings = $this->get_settings();
$is_checked = $settings['app_passwords_require_2fa_creation'];
printf(
'<input type="hidden" name="%1$s[app_passwords_require_2fa_creation]" value="0" />',
esc_attr( self::OPTION_NAME )
);
printf(
'<label><input type="checkbox" name="%1$s[app_passwords_require_2fa_creation]" value="1" %2$s /> %3$s</label>',
esc_attr( self::OPTION_NAME ),
checked( $is_checked, true, false ),
esc_html__( 'Require a recent 2FA verification before creating a new Application Password.', 'robotstxt-2fa' )
);
echo '<p class="description">' . esc_html__( 'When enabled, users must have completed a 2FA challenge within the last 15 minutes before they can generate a new Application Password via the REST API.', 'robotstxt-2fa' ) . '</p>';
}
/**
* Render the GeoIP section description.
*
* @return void
*/
public function render_geoip_section(): void {
echo '<p>' . esc_html__( 'Requires a MaxMind GeoLite2 Country database file (.mmdb). Leave empty to disable country-based rules. Download the free GeoLite2 Country database from maxmind.com.', 'robotstxt-2fa' ) . '</p>';
}
/**
* Render the GeoIP database path field.
*
* @return void
*/
public function render_geoip_database_path_field(): void {
$settings = $this->get_settings();
printf(
'<input type="text" name="%1$s[geoip_database_path]" value="%2$s" size="60" />',
esc_attr( self::OPTION_NAME ),
esc_attr( $settings['geoip_database_path'] )
);
echo '<p class="description">' . esc_html__( 'Absolute path to the GeoLite2-Country.mmdb file. Leave empty to disable GeoIP features.', 'robotstxt-2fa' ) . '</p>';
}
/**
* Render the GeoIP country allow list textarea.
*
* @return void
*/
public function render_geoip_country_allow_field(): void {
$settings = $this->get_settings();
printf(
'<textarea name="%1$s[geoip_country_allow]" rows="3" cols="40">%2$s</textarea>',
esc_attr( self::OPTION_NAME ),
esc_textarea( $settings['geoip_country_allow'] )
);
echo '<p class="description">' . esc_html__( 'ISO country codes (one per line, e.g. ES, US) whose logins bypass the 2FA challenge.', 'robotstxt-2fa' ) . '</p>';
}
/**
* Render the GeoIP country deny list textarea.
*
* @return void
*/
public function render_geoip_country_deny_field(): void {
$settings = $this->get_settings();
printf(
'<textarea name="%1$s[geoip_country_deny]" rows="3" cols="40">%2$s</textarea>',
esc_attr( self::OPTION_NAME ),
esc_textarea( $settings['geoip_country_deny'] )
);
echo '<p class="description">' . esc_html__( 'ISO country codes blocked from logging in altogether.', 'robotstxt-2fa' ) . '</p>';
}
/**
* Render the GeoIP always-challenge countries textarea.
*
* @return void
*/
public function render_geoip_always_challenge_field(): void {
$settings = $this->get_settings();
printf(
'<textarea name="%1$s[geoip_always_challenge]" rows="3" cols="40">%2$s</textarea>',
esc_attr( self::OPTION_NAME ),
esc_textarea( $settings['geoip_always_challenge'] )
);
echo '<p class="description">' . esc_html__( 'ISO country codes that always trigger a 2FA challenge, regardless of the verification frequency setting.', 'robotstxt-2fa' ) . '</p>';
}
/**
* Render the Documentation page.
*

View file

@ -0,0 +1,357 @@
<?php
/**
* WP_List_Table subclass for the 2FA audit dashboard.
*
* @package Robotstxt_2FA
*/
namespace Robotstxt\TwoFA\Admin;
use Robotstxt\TwoFA\User\Two_Factor_Config;
use Robotstxt\TwoFA\User\User_Settings_Repository;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'WP_List_Table' ) ) {
require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
}
/**
* Displays all users with their 2FA status in a sortable, filterable table.
*
* @since 1.5.0
*/
class Users_List_Table extends \WP_List_Table {
/**
* Global two-factor configuration.
*
* @var Two_Factor_Config
*/
private Two_Factor_Config $config;
/**
* User settings repository.
*
* @var User_Settings_Repository
*/
private User_Settings_Repository $repository;
/**
* Constructor.
*
* @param Two_Factor_Config $config Global two-factor configuration.
* @param User_Settings_Repository $repository User settings repository.
*/
public function __construct( Two_Factor_Config $config, User_Settings_Repository $repository ) {
parent::__construct(
array(
'singular' => 'user',
'plural' => 'users',
'ajax' => false,
)
);
$this->config = $config;
$this->repository = $repository;
}
/**
* Return the list of columns.
*
* @since 1.5.0
*
* @return array<string, string>
*/
public function get_columns(): array {
return array(
'cb' => '<input type="checkbox" />',
'user' => __( 'User', 'robotstxt-2fa' ),
'roles' => __( 'Role', 'robotstxt-2fa' ),
'status' => __( '2FA Status', 'robotstxt-2fa' ),
'methods' => __( 'Methods', 'robotstxt-2fa' ),
'last_verified' => __( 'Last verified', 'robotstxt-2fa' ),
'unused_codes' => __( 'Unused codes', 'robotstxt-2fa' ),
);
}
/**
* Return the list of sortable columns.
*
* @since 1.5.0
*
* @return array<string, array{string, bool}>
*/
public function get_sortable_columns(): array {
return array(
'user' => array( 'user_login', false ),
'last_verified' => array( 'last_verified', true ),
);
}
/**
* Render the checkbox column.
*
* @since 1.5.0
*
* @param mixed $item Current row data.
*
* @return string
*/
public function column_cb( mixed $item ): string {
if ( ! is_array( $item ) ) {
return '';
}
$raw_id = $item['ID'] ?? 0;
$item_id = is_numeric( $raw_id ) ? (int) $raw_id : 0;
return sprintf(
'<input type="checkbox" name="users[]" value="%s" />',
absint( $item_id )
);
}
/**
* Render the user column with login, email, and edit link.
*
* @since 1.5.0
*
* @param mixed $item Current row data.
*
* @return string
*/
public function column_user( mixed $item ): string {
if ( ! is_array( $item ) ) {
return '';
}
$raw_id = $item['ID'] ?? 0;
$item_id = is_numeric( $raw_id ) ? (int) $raw_id : 0;
$edit_link = get_edit_user_link( $item_id );
$raw_login = $item['user_login'] ?? '';
$login = esc_html( is_string( $raw_login ) ? $raw_login : '' );
$raw_email = $item['user_email'] ?? '';
$email = esc_html( is_string( $raw_email ) ? $raw_email : '' );
$output = '<strong>';
if ( '' !== $edit_link ) {
$output .= '<a href="' . esc_url( $edit_link ) . '">' . $login . '</a>';
} else {
$output .= $login;
}
$output .= '</strong><br /><span class="description">' . $email . '</span>';
return $output;
}
/**
* Render a default column value.
*
* @since 1.5.0
*
* @param mixed $item Current row data.
* @param mixed $column_name Column identifier.
*
* @return string
*/
public function column_default( mixed $item, mixed $column_name ): string {
if ( ! is_array( $item ) || ! is_string( $column_name ) ) {
return '';
}
$raw_value = $item[ $column_name ] ?? '';
return esc_html( is_string( $raw_value ) ? $raw_value : '' );
}
/**
* Return the available bulk actions.
*
* @since 1.5.0
*
* @return array<string, string>
*/
public function get_bulk_actions(): array {
return array(
'export_csv' => __( 'Export CSV', 'robotstxt-2fa' ),
);
}
/**
* Prepare the items for display: query users, compute 2FA status, sort, paginate.
*
* @since 1.5.0
*
* @return void
*/
public function prepare_items(): void {
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- GET display params only; no state changes.
$role = isset( $_REQUEST['role_filter'] ) && is_string( $_REQUEST['role_filter'] ) ? sanitize_key( $_REQUEST['role_filter'] ) : '';
$search = isset( $_REQUEST['s'] ) && is_string( $_REQUEST['s'] ) ? sanitize_text_field( wp_unslash( $_REQUEST['s'] ) ) : '';
$status_filter = isset( $_REQUEST['status_filter'] ) && is_string( $_REQUEST['status_filter'] ) ? sanitize_key( $_REQUEST['status_filter'] ) : '';
$orderby = isset( $_REQUEST['orderby'] ) && is_string( $_REQUEST['orderby'] ) ? sanitize_key( $_REQUEST['orderby'] ) : 'user_login';
$raw_order = isset( $_REQUEST['order'] ) && is_string( $_REQUEST['order'] ) ? strtolower( sanitize_key( $_REQUEST['order'] ) ) : 'asc';
$order = in_array( $raw_order, array( 'asc', 'desc' ), true ) ? $raw_order : 'asc';
$paged = isset( $_REQUEST['paged'] ) && is_numeric( $_REQUEST['paged'] ) ? max( 1, (int) $_REQUEST['paged'] ) : 1;
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$query_args = array(
'number' => -1,
'fields' => 'all',
);
if ( '' !== $role ) {
$query_args['role'] = $role;
}
if ( '' !== $search ) {
$query_args['search'] = '*' . $search . '*';
}
$users = get_users( $query_args );
$rows = array();
foreach ( $users as $user ) {
if ( ! $user instanceof \WP_User ) {
continue;
}
$settings = $this->repository->get_user_settings( $user->ID );
$is_enabled = $settings['enabled'];
$required_methods = $this->config->get_required_methods_for_user( $user );
$is_forced = ! empty( $required_methods );
if ( $is_enabled ) {
$status = 'active';
} elseif ( $is_forced ) {
$status = 'required';
} else {
$status = 'optional';
}
// Compute last verified timestamp across all methods/contexts.
$last_verified_ts = 0;
$raw_verifications = get_user_meta( $user->ID, 'robotstxt_2fa_last_verifications', true );
if ( is_array( $raw_verifications ) ) {
foreach ( $raw_verifications as $method_data ) {
if ( is_array( $method_data ) ) {
foreach ( $method_data as $context_data ) {
if ( is_array( $context_data ) && isset( $context_data['verified_at'] ) && is_int( $context_data['verified_at'] ) ) {
$last_verified_ts = max( $last_verified_ts, $context_data['verified_at'] );
}
}
}
}
}
$last_verified_str = $last_verified_ts > 0 ? (string) wp_date( 'Y-m-d H:i', $last_verified_ts ) : '—';
// Count unused recovery codes.
$unused_codes = 0;
$raw_codes = get_user_meta( $user->ID, 'robotstxt_2fa_recovery_codes', true );
if ( is_array( $raw_codes ) && isset( $raw_codes['codes'] ) && is_array( $raw_codes['codes'] ) ) {
foreach ( $raw_codes['codes'] as $code_entry ) {
if ( is_array( $code_entry ) && empty( $code_entry['used_at'] ) ) {
++$unused_codes;
}
}
}
$rows[] = array(
'ID' => $user->ID,
'user_login' => $user->user_login,
'user_email' => $user->user_email,
'roles' => implode( ', ', $user->roles ),
'status' => $status,
'methods' => implode( ', ', $settings['methods'] ),
'last_verified' => $last_verified_str,
'unused_codes' => (string) $unused_codes,
);
}
// Filter by status.
if ( '' !== $status_filter ) {
$rows = array_values(
array_filter(
$rows,
static function ( array $row ) use ( $status_filter ): bool {
return $row['status'] === $status_filter;
}
)
);
}
// Sort.
usort(
$rows,
static function ( array $a, array $b ) use ( $orderby, $order ): int {
$val_a = (string) ( $a[ $orderby ] ?? '' );
$val_b = (string) ( $b[ $orderby ] ?? '' );
$cmp = strcmp( $val_a, $val_b );
return 'desc' === $order ? -$cmp : $cmp;
}
);
$total_items = count( $rows );
$per_page = 20;
$offset = ( $paged - 1 ) * $per_page;
$this->items = array_slice( $rows, $offset, $per_page );
$this->set_pagination_args(
array(
'total_items' => $total_items,
'per_page' => $per_page,
)
);
}
/**
* Render extra table navigation filters.
*
* @since 1.5.0
*
* @param mixed $which Which tablenav ('top' or 'bottom').
*
* @return void
*/
public function extra_tablenav( mixed $which ): void {
if ( 'top' !== $which ) {
return;
}
// phpcs:disable WordPress.Security.NonceVerification.Recommended -- GET display params only; no state changes.
$current_role = isset( $_REQUEST['role_filter'] ) && is_string( $_REQUEST['role_filter'] ) ? sanitize_key( $_REQUEST['role_filter'] ) : '';
$current_status = isset( $_REQUEST['status_filter'] ) && is_string( $_REQUEST['status_filter'] ) ? sanitize_key( $_REQUEST['status_filter'] ) : '';
// phpcs:enable WordPress.Security.NonceVerification.Recommended
$roles = get_editable_roles();
?>
<div class="alignleft actions">
<select name="role_filter">
<option value=""><?php esc_html_e( '— All roles —', 'robotstxt-2fa' ); ?></option>
<?php foreach ( $roles as $role_key => $role_info ) : ?>
<option value="<?php echo esc_attr( $role_key ); ?>" <?php selected( $current_role, $role_key ); ?>>
<?php echo esc_html( translate_user_role( $role_info['name'] ) ); ?>
</option>
<?php endforeach; ?>
</select>
<select name="status_filter">
<option value=""><?php esc_html_e( '— All statuses —', 'robotstxt-2fa' ); ?></option>
<option value="active" <?php selected( $current_status, 'active' ); ?>><?php esc_html_e( 'Active', 'robotstxt-2fa' ); ?></option>
<option value="required" <?php selected( $current_status, 'required' ); ?>><?php esc_html_e( 'Required (not set up)', 'robotstxt-2fa' ); ?></option>
<option value="optional" <?php selected( $current_status, 'optional' ); ?>><?php esc_html_e( 'Optional (disabled)', 'robotstxt-2fa' ); ?></option>
</select>
<?php submit_button( __( 'Filter', 'robotstxt-2fa' ), '', 'filter_action', false ); ?>
</div>
<?php
}
}

View file

@ -84,23 +84,28 @@ class Email_Notifications {
/**
* Schedule or unschedule the digest cron event based on settings.
*
* Also reschedules when the frequency setting has changed.
*
* @since 1.3.0
*
* @return void
*/
public function maybe_schedule_digest(): void {
$notifications = $this->config->get_notifications();
$digest_enabled = $notifications['digest_enabled'];
$digest_frequency = $notifications['digest_frequency'];
$next_scheduled = wp_next_scheduled( self::DIGEST_CRON_HOOK );
$notifications = $this->config->get_notifications();
$digest_enabled = $notifications['digest_enabled'];
if ( $digest_enabled ) {
if ( false === $next_scheduled ) {
$interval = 'monthly' === $digest_frequency ? 'robotstxt_2fa_monthly' : 'weekly';
$interval = 'monthly' === $notifications['digest_frequency'] ? 'robotstxt_2fa_monthly' : 'weekly';
$scheduled_event = wp_get_scheduled_event( self::DIGEST_CRON_HOOK );
if ( false === $scheduled_event ) {
wp_schedule_event( time() + DAY_IN_SECONDS, $interval, self::DIGEST_CRON_HOOK );
} elseif ( isset( $scheduled_event->schedule ) && is_string( $scheduled_event->schedule ) && $scheduled_event->schedule !== $interval ) {
wp_clear_scheduled_hook( self::DIGEST_CRON_HOOK );
wp_schedule_event( time() + DAY_IN_SECONDS, $interval, self::DIGEST_CRON_HOOK );
}
} elseif ( false !== $next_scheduled ) {
wp_clear_scheduled_hook( self::DIGEST_CRON_HOOK );
} elseif ( (bool) wp_next_scheduled( self::DIGEST_CRON_HOOK ) ) {
wp_clear_scheduled_hook( self::DIGEST_CRON_HOOK );
}
}

View file

@ -0,0 +1,222 @@
<?php
/**
* GeoIP-based country restrictions for the 2FA challenge.
*
* @package Robotstxt_2FA
*/
namespace Robotstxt\TwoFA;
use Robotstxt\TwoFA\User\Two_Factor_Config;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Applies country-based allow/deny/force-challenge rules using MaxMind GeoIP.
*
* @since 1.5.0
*/
class Geo_Restrictions {
/**
* Global two-factor configuration.
*
* @var Two_Factor_Config
*/
private Two_Factor_Config $config;
/**
* Constructor.
*
* @param Two_Factor_Config $config Global two-factor configuration.
*/
public function __construct( Two_Factor_Config $config ) {
$this->config = $config;
}
/**
* Register WordPress hooks.
*
* @since 1.5.0
*
* @return void
*/
public function register_hooks(): void {
add_filter( 'robotstxt_2fa_skip_challenge', array( $this, 'maybe_skip_for_allowed_country' ), 6, 2 );
add_filter( 'authenticate', array( $this, 'maybe_block_denied_country' ), 2, 3 );
add_filter( 'robotstxt_2fa_force_challenge', array( $this, 'maybe_force_challenge_for_country' ), 10, 2 );
}
/**
* Skip the 2FA challenge for users logging in from an allowed country.
*
* @since 1.5.0
*
* @param bool $skip Whether the challenge is already being skipped.
* @param \WP_User $user Authenticated user about to be challenged.
*
* @return bool
*/
public function maybe_skip_for_allowed_country( bool $skip, \WP_User $user ): bool {
unset( $user );
if ( $skip ) {
return true;
}
$allow_list = $this->config->get_geoip_country_allow();
if ( '' === $allow_list ) {
return false;
}
$country = $this->get_country_for_ip();
if ( '' === $country ) {
return false;
}
return $this->country_in_list( $country, $allow_list );
}
/**
* Block logins from denied countries before credentials are checked.
*
* @since 1.5.0
*
* @param mixed $user Previously authenticated user or null.
* @param string $username Submitted username.
* @param string $password Submitted password.
*
* @return mixed
*/
public function maybe_block_denied_country( mixed $user, string $username, string $password ): mixed {
unset( $username, $password );
$deny_list = $this->config->get_geoip_country_deny();
if ( '' === $deny_list ) {
return $user;
}
$country = $this->get_country_for_ip();
if ( '' === $country ) {
return $user;
}
if ( $this->country_in_list( $country, $deny_list ) ) {
return new \WP_Error(
'robotstxt_2fa_country_blocked',
__( 'Login is not allowed from your country.', 'robotstxt-2fa' )
);
}
return $user;
}
/**
* Force a fresh 2FA challenge for users logging in from a high-risk country.
*
* @since 1.5.0
*
* @param bool $force Whether the challenge is already being forced.
* @param \WP_User $user User about to be challenged.
*
* @return bool
*/
public function maybe_force_challenge_for_country( bool $force, \WP_User $user ): bool {
unset( $user );
if ( $force ) {
return true;
}
$always_challenge = $this->config->get_geoip_always_challenge();
if ( '' === $always_challenge ) {
return false;
}
$country = $this->get_country_for_ip();
if ( '' === $country ) {
return false;
}
return $this->country_in_list( $country, $always_challenge );
}
/**
* Resolve the ISO 3166-1 alpha-2 country code for the current request IP.
*
* Returns an empty string when GeoIP is unavailable or the lookup fails.
*
* @since 1.5.0
*
* @return string
*/
private function get_country_for_ip(): string {
$db_path = $this->config->get_geoip_database_path();
if ( '' === $db_path || ! file_exists( $db_path ) ) {
return '';
}
if ( ! class_exists( '\MaxMind\Db\Reader' ) ) {
return '';
}
$ip = '';
if ( isset( $_SERVER['REMOTE_ADDR'] ) && is_string( $_SERVER['REMOTE_ADDR'] ) ) {
$ip = sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) );
}
if ( '' === $ip ) {
return '';
}
try {
$reader = new \MaxMind\Db\Reader( $db_path );
$record = $reader->get( $ip );
$reader->close();
if ( ! is_array( $record ) ) {
return '';
}
$country = $record['country'] ?? null;
if ( ! is_array( $country ) || ! isset( $country['iso_code'] ) || ! is_string( $country['iso_code'] ) ) {
return '';
}
return strtoupper( $country['iso_code'] );
} catch ( \Throwable $e ) {
return '';
}
}
/**
* Check whether a country code appears in a newline/comma-separated list.
*
* @since 1.5.0
*
* @param string $country ISO 3166-1 alpha-2 country code (uppercase).
* @param string $codelist Newline- or comma-separated country codes.
*
* @return bool
*/
private function country_in_list( string $country, string $codelist ): bool {
if ( '' === $country || '' === $codelist ) {
return false;
}
$split_result = preg_split( '/[\s,]+/', strtoupper( $codelist ) );
$codes = array_filter( array_map( 'trim', is_array( $split_result ) ? $split_result : array() ) );
return in_array( $country, $codes, true );
}
}

View file

@ -17,6 +17,7 @@ use Robotstxt\TwoFA\User\Profile_Settings;
use Robotstxt\TwoFA\User\Recovery_Codes;
use Robotstxt\TwoFA\User\Trusted_Devices;
use Robotstxt\TwoFA\User\Two_Factor_Config;
use Robotstxt\TwoFA\User\User_Settings_Repository;
if ( ! defined( 'ABSPATH' ) ) {
exit;
@ -103,6 +104,13 @@ class Plugin {
*/
private IP_Restrictions $ip_restrictions;
/**
* GeoIP country restrictions handler.
*
* @var Geo_Restrictions
*/
private Geo_Restrictions $geo_restrictions;
/**
* Audit dashboard page.
*
@ -128,6 +136,7 @@ class Plugin {
*/
public function __construct() {
$config = new Two_Factor_Config();
$repository = new User_Settings_Repository();
$this->attempts_log = new Attempts_Log();
$this->login_manager = new Login_Form_Manager();
$this->profile_settings = new Profile_Settings();
@ -138,7 +147,8 @@ class Plugin {
$this->grace_period = new Grace_Period();
$this->email_notifications = new Email_Notifications( $config );
$this->ip_restrictions = new IP_Restrictions( $config );
$this->dashboard_page = new Dashboard_Page( $this->attempts_log );
$this->geo_restrictions = new Geo_Restrictions( $config );
$this->dashboard_page = new Dashboard_Page( $this->attempts_log, $config, $repository );
}
/**
@ -151,6 +161,7 @@ class Plugin {
$this->attempts_log->register_hooks();
$this->email_notifications->register_hooks();
$this->ip_restrictions->register_hooks();
$this->geo_restrictions->register_hooks();
$this->dashboard_page->register_hooks();
$this->login_manager->register_hooks();
$this->profile_settings->register_hooks();
@ -160,11 +171,86 @@ class Plugin {
$this->trusted_devices->register_hooks();
$this->grace_period->register_hooks();
add_filter( 'rest_pre_dispatch', array( $this, 'maybe_block_app_password_creation' ), 10, 3 );
if ( defined( 'WP_CLI' ) && WP_CLI ) {
add_action( 'cli_init', array( $this, 'register_cli_commands' ) );
}
}
/**
* Block Application Password creation when the user has not recently verified 2FA.
*
* @since 1.5.0
*
* @param mixed $result Current result (null = not yet dispatched).
* @param \WP_REST_Server $server REST server instance.
* @param \WP_REST_Request $request Current request.
*
* @return mixed
*/
public function maybe_block_app_password_creation( mixed $result, \WP_REST_Server $server, \WP_REST_Request $request ): mixed {
unset( $server );
if ( null !== $result ) {
return $result;
}
if ( 'POST' !== $request->get_method() ) {
return $result;
}
$config = new Two_Factor_Config();
if ( ! $config->is_app_passwords_require_2fa_creation() ) {
return $result;
}
if ( ! preg_match( '#^/wp/v2/users/\d+/application-passwords$#', $request->get_route() ) ) {
return $result;
}
$user = wp_get_current_user();
if ( ! $user->exists() ) {
return $result;
}
$verified_at = 0;
$raw = get_user_meta( $user->ID, 'robotstxt_2fa_last_verifications', true );
if ( is_array( $raw ) ) {
foreach ( $raw as $method_data ) {
if ( is_array( $method_data ) ) {
foreach ( $method_data as $context_data ) {
if ( is_array( $context_data ) && isset( $context_data['verified_at'] ) && is_int( $context_data['verified_at'] ) ) {
$verified_at = max( $verified_at, $context_data['verified_at'] );
}
}
}
}
}
/**
* Filter the 2FA recency window (in seconds) required before creating an Application Password.
*
* @since 1.5.0
*
* @param int $window Seconds since last 2FA verification. Default 900 (15 minutes).
*/
$window = (int) apply_filters( 'robotstxt_2fa_app_password_verification_window', 900 );
if ( $verified_at > 0 && ( time() - $verified_at ) <= $window ) {
return $result;
}
return new \WP_Error(
'robotstxt_2fa_required',
__( 'A recent two-factor authentication verification is required to create an Application Password. Please log in and complete 2FA, then try again.', 'robotstxt-2fa' ),
array( 'status' => 401 )
);
}
/**
* Register WP-CLI commands.
*

View file

@ -310,6 +310,37 @@ class Cli_Command extends WP_CLI_Command {
\WP_CLI\Utils\format_items( 'table', $rows, array( 'ID', 'Login', 'Email', '2FA', 'Frequency' ) );
}
/**
* Export a full 2FA status report for all users.
*
* Equivalent to `wp 2fa list --format=csv` but outputs to stdout for easy
* redirection to a file.
*
* ## OPTIONS
*
* [--role=<role>]
* : Restrict export to a specific WordPress role.
*
* [--without-2fa]
* : Include only users who do not have 2FA enabled.
*
* ## EXAMPLES
*
* wp 2fa export > 2fa-audit.csv
* wp 2fa export --role=editor > editors.csv
*
* @since 1.5.0
*
* @param array<int, string> $args Positional arguments.
* @param array<string, string> $assoc_args Associative arguments.
*
* @return void
*/
public function export( array $args, array $assoc_args ): void {
$assoc_args['format'] = 'csv';
$this->list_users( $args, $assoc_args );
}
/**
* Enforce 2FA for a specific user or all users of a role.
*

View file

@ -1043,7 +1043,20 @@ class Login_Form_Manager {
$frequency = $this->get_effective_frequency( $user, $user_settings );
if ( $this->has_recent_verification( $user, $methods, $frequency ) ) {
return '';
/**
* Filter whether to force a fresh 2FA challenge regardless of the frequency setting.
*
* Return true to always challenge the user, overriding the frequency-based skip.
* Used by GeoIP restrictions to mandate verification from new countries.
*
* @since 1.5.0
*
* @param bool $force Whether to force the challenge. Default false.
* @param \WP_User $user User about to be challenged.
*/
if ( ! (bool) apply_filters( 'robotstxt_2fa_force_challenge', false, $user ) ) {
return '';
}
}
return $this->select_preferred_method( $methods );

View file

@ -21,7 +21,7 @@ class Two_Factor_Config {
/**
* Retrieve global two-factor settings with multisite support.
*
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}}
* @return array{role_methods: array<string, array<int, string>>, frequency: string, force_frequency: bool, delete_on_uninstall: bool, max_attempts: int, lockout_duration: int, trust_device_days: int, grace_period_days: int, grace_period_action: string, app_passwords_exempt: bool, ip_allow: string, ip_deny: string, notifications: array{on_enable: bool, on_new_ip: bool, on_recovery_used: bool, on_recovery_used_admin: bool, digest_enabled: bool, digest_frequency: string}, app_passwords_require_2fa_creation: bool, geoip_database_path: string, geoip_country_allow: string, geoip_country_deny: string, geoip_always_challenge: string}
*/
public function get_settings(): array {
$settings_page = new Settings_Page();
@ -225,4 +225,59 @@ class Two_Factor_Config {
public function get_notifications(): array {
return $this->get_settings()['notifications'];
}
/**
* Determine whether a recent 2FA verification is required before creating an Application Password.
*
* @since 1.5.0
*
* @return bool
*/
public function is_app_passwords_require_2fa_creation(): bool {
return $this->get_settings()['app_passwords_require_2fa_creation'];
}
/**
* Retrieve the GeoIP database file path.
*
* @since 1.5.0
*
* @return string
*/
public function get_geoip_database_path(): string {
return $this->get_settings()['geoip_database_path'];
}
/**
* Retrieve the GeoIP country allow list string (newline-separated ISO codes).
*
* @since 1.5.0
*
* @return string
*/
public function get_geoip_country_allow(): string {
return $this->get_settings()['geoip_country_allow'];
}
/**
* Retrieve the GeoIP country deny list string (newline-separated ISO codes).
*
* @since 1.5.0
*
* @return string
*/
public function get_geoip_country_deny(): string {
return $this->get_settings()['geoip_country_deny'];
}
/**
* Retrieve the GeoIP always-challenge country list string (newline-separated ISO codes).
*
* @since 1.5.0
*
* @return string
*/
public function get_geoip_always_challenge(): string {
return $this->get_settings()['geoip_always_challenge'];
}
}