v1.6.9
This commit is contained in:
parent
1ff471299e
commit
7379505d20
4 changed files with 912 additions and 139 deletions
|
|
@ -24,6 +24,18 @@ class Dashboard_Page {
|
|||
*/
|
||||
public const PAGE_SLUG = 'robotstxt-2fa-dashboard';
|
||||
|
||||
/**
|
||||
* Brand SVG menu icon (shield with keyhole) as a base64 data URI.
|
||||
*
|
||||
* WordPress core renders base64-encoded SVG data URIs natively in admin
|
||||
* menus (centered at 20px via the .wp-menu-image.svg CSS class), which
|
||||
* keeps the icon crisp and independent of the Dashicons font while
|
||||
* remaining fully backward compatible.
|
||||
*
|
||||
* @since 1.6.9
|
||||
*/
|
||||
public const MENU_ICON = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDIwIDIwIiByb2xlPSJpbWciIGFyaWEtaGlkZGVuPSJ0cnVlIiBmb2N1c2FibGU9ImZhbHNlIj48cGF0aCBmaWxsPSIjMDM4N2M5IiBkPSJNMTAgMSAxOCAzLjl2NS4zYzAgNS40LTMuMyA4LjYtOCA5LjgtNC43LTEuMi04LTQuNC04LTkuOFYzLjlaIi8+PGNpcmNsZSBjeD0iMTAiIGN5PSI4IiByPSIyLjIiIGZpbGw9IiNmZmVmZDQiLz48cGF0aCBmaWxsPSIjZmZlZmQ0IiBkPSJNOC44IDkuOSA3LjYgMTMuN2g0LjhMMTEuMiA5LjlaIi8+PC9zdmc+';
|
||||
|
||||
/**
|
||||
* Failed attempts log.
|
||||
*
|
||||
|
|
@ -108,7 +120,7 @@ class Dashboard_Page {
|
|||
'manage_options',
|
||||
self::PAGE_SLUG,
|
||||
array( $this, 'render_page' ),
|
||||
'dashicons-shield'
|
||||
self::MENU_ICON
|
||||
);
|
||||
|
||||
add_submenu_page(
|
||||
|
|
|
|||
|
|
@ -538,6 +538,11 @@ class Migration_Page {
|
|||
* @return array<int, array{user: \WP_User, source: string}>
|
||||
*/
|
||||
private function get_candidates_from_wordfence(): array {
|
||||
/**
|
||||
* WordPress database abstraction. Typed for PHPStan level max.
|
||||
*
|
||||
* @var \wpdb $wpdb
|
||||
*/
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->prefix . self::WORDFENCE_TABLE;
|
||||
|
|
@ -550,21 +555,17 @@ class Migration_Page {
|
|||
return array();
|
||||
}
|
||||
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table names are trusted constants.
|
||||
// phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is a trusted prefix constant; the user ID is a validated integer.
|
||||
$rows = $wpdb->get_results(
|
||||
"SELECT s.user_id, s.secret FROM `{$table}` s",
|
||||
ARRAY_A
|
||||
);
|
||||
// phpcs:enable WordPress.DB.PreparedSQL.InterpolatedNotPrepared
|
||||
|
||||
if ( ! is_array( $rows ) ) {
|
||||
return array();
|
||||
}
|
||||
|
||||
$candidates = array();
|
||||
|
||||
foreach ( $rows as $row ) {
|
||||
if ( ! is_array( $row ) || ! isset( $row['user_id'] ) || ! is_numeric( $row['user_id'] ) ) {
|
||||
if ( ! isset( $row['user_id'] ) || ! is_numeric( $row['user_id'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -716,14 +717,19 @@ class Migration_Page {
|
|||
* @return string
|
||||
*/
|
||||
private function read_wordfence_secret( int $user_id ): string {
|
||||
/**
|
||||
* WordPress database abstraction. Typed for PHPStan level max.
|
||||
*
|
||||
* @var \wpdb $wpdb
|
||||
*/
|
||||
global $wpdb;
|
||||
|
||||
$table = $wpdb->prefix . self::WORDFENCE_TABLE;
|
||||
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is a trusted constant.
|
||||
$secret_binary = $wpdb->get_var( $wpdb->prepare( "SELECT `secret` FROM `{$table}` WHERE `user_id` = %d LIMIT 1", $user_id ) );
|
||||
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Table name is a trusted prefix constant; the user ID is a validated integer.
|
||||
$secret_binary = $wpdb->get_var( "SELECT `secret` FROM `{$table}` WHERE `user_id` = {$user_id} LIMIT 1" );
|
||||
|
||||
if ( ! is_string( $secret_binary ) || '' === $secret_binary ) {
|
||||
if ( ! is_string( $secret_binary ) ) {
|
||||
return '';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -431,8 +431,13 @@ class Settings_Page {
|
|||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ( $roles as $role_key => $role_details ) : ?>
|
||||
<?php
|
||||
$role_name = isset( $role_details['name'] ) && is_string( $role_details['name'] )
|
||||
? $role_details['name']
|
||||
: $role_key;
|
||||
?>
|
||||
<tr data-2fa-role="<?php echo esc_attr( $role_key ); ?>">
|
||||
<td><?php echo esc_html( translate_user_role( $role_details['name'] ) ); ?></td>
|
||||
<td><?php echo esc_html( translate_user_role( $role_name ) ); ?></td>
|
||||
<?php foreach ( $methods as $method_key => $method_label ) : ?>
|
||||
<td style="text-align:center;">
|
||||
<label>
|
||||
|
|
@ -441,7 +446,7 @@ class Settings_Page {
|
|||
printf(
|
||||
/* translators: 1: role name, 2: method name. */
|
||||
esc_html__( '%1$s: require %2$s', 'robotstxt-2fa' ),
|
||||
esc_html( translate_user_role( $role_details['name'] ) ),
|
||||
esc_html( translate_user_role( $role_name ) ),
|
||||
esc_html( $method_label )
|
||||
);
|
||||
?>
|
||||
|
|
@ -802,7 +807,7 @@ class Settings_Page {
|
|||
/**
|
||||
* Resolve role_methods from stored options, migrating legacy force_roles + default_method if needed.
|
||||
*
|
||||
* @param array<string, mixed> $options Raw stored options.
|
||||
* @param array<mixed> $options Raw stored options (untyped values from the options table).
|
||||
*
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
|
|
@ -1145,7 +1150,7 @@ class Settings_Page {
|
|||
$capability,
|
||||
self::PAGE_SLUG,
|
||||
array( $this, 'render_page' ),
|
||||
'dashicons-shield'
|
||||
Dashboard_Page::MENU_ICON
|
||||
);
|
||||
|
||||
// Rename the first auto-created submenu entry to "Settings".
|
||||
|
|
|
|||
|
|
@ -338,9 +338,14 @@ class Users_List_Table extends \WP_List_Table {
|
|||
<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 ) : ?>
|
||||
<?php
|
||||
foreach ( $roles as $role_key => $role_info ) :
|
||||
$role_name = isset( $role_info['name'] ) && is_string( $role_info['name'] )
|
||||
? $role_info['name']
|
||||
: $role_key;
|
||||
?>
|
||||
<option value="<?php echo esc_attr( $role_key ); ?>" <?php selected( $current_role, $role_key ); ?>>
|
||||
<?php echo esc_html( translate_user_role( $role_info['name'] ) ); ?>
|
||||
<?php echo esc_html( translate_user_role( $role_name ) ); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
|
|
|
|||
Loading…
Reference in a new issue