Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Two Factor Authentication 1.3.10 WordPress plugin - Patch for adding TFA status to users list
diff --git a/css/users.css b/css/users.css
new file mode 100644
index 0000000..ca7d3f0
--- /dev/null
+++ b/css/users.css
@@ -0,0 +1,13 @@
+/* TFA users list column */
+th.column-tfa-status,
+td.column-tfa-status {
+ text-align: center;
+}
+
+td.column-tfa-status span.dashicons-no {
+ color: red;
+}
+
+td.column-tfa-status span.dashicons-yes {
+ color: green;
+}
\ No newline at end of file
diff --git a/two-factor-login.php b/two-factor-login.php
index 201c018..75fe097 100644
--- a/two-factor-login.php
+++ b/two-factor-login.php
@@ -78,6 +78,13 @@ class Simba_Two_Factor_Authentication {
add_action('network_admin_menu', array($this, 'admin_menu'));
add_action('admin_menu', array($this, 'admin_menu'));
+ // Add TFA column on users list.
+ add_action( 'manage_users_columns', array( $this, 'manageUsersColumnsTFA' ), 10, 1 );
+ add_action( 'manage_users_custom_column', array( $this, 'manageUsersCustomColumnTFA' ), 10, 3 );
+
+ // Needed users.php CSS.
+ add_action( 'admin_print_styles-users.php', array( $this, 'load_users_css' ), 10, 0 );
+
} else {
add_action('init', array($this, 'check_possible_reset'));
}
@@ -304,7 +311,7 @@ class Simba_Two_Factor_Authentication {
if ($tfa->isRequiredForUser($user_id)) {
$requireafter = absint($this->get_option('tfa_requireafter'));
- echo '<p class="tfa_required_warning" style="font-weight:bold; font-style:italics;">'.sprintf(__('N.B. This site is configured to forbid you to log in if you disable two-factor authentication after your account is %d days old', 'two-factor-authentication'), $requireafter).'</p>';
+ echo '<p class="tfa_required_warning" style="font-weight:bold; font-style:italic;">'.sprintf(__('N.B. This site is configured to forbid you to log in if you disable two-factor authentication after your account is %d days old', 'two-factor-authentication'), $requireafter).'</p>';
}
$tfa_enabled_label = ($long_label) ? __('Enable two-factor authentication', 'two-factor-authentication') : __('Enabled', 'two-factor-authentication');
@@ -953,6 +960,74 @@ class Simba_Two_Factor_Authentication {
return $whatever;
}
+ /**
+ * Load CSS files.
+ *
+ * @return void
+ */
+ public function load_users_css() {
+ wp_enqueue_style(
+ 'tfa-users-css',
+ SIMBA_TFA_PLUGIN_URL . '/css/users.css',
+ array(),
+ $this->version,
+ 'screen'
+ );
+ }
+
+ /**
+ * Add the 2TA label to the users list table header.
+ *
+ * @since 1.3.11
+ *
+ * @param array $colums Table columns.
+ *
+ * @return array
+ */
+ public function manageUsersColumnsTFA ( $columns = array() ) {
+
+ // Add the group
+ $columns['tfa-status'] = __( 'Two-Factor', 'two-factor-authentication' );
+
+ // Return columns
+ return $columns;
+ }
+
+ /**
+ * Add status into TFA column.
+ *
+ * @since 1.3.11
+ *
+ * @param string $value String.
+ * @param string $column_name Column name.
+ * @param integer $user_id User ID.
+ *
+ * @return string
+ */
+ public function manageUsersCustomColumnTFA ( $value = '', $column_name = '', $user_id = 0 ) {
+
+ // Only for this column name.
+ if ( 'tfa-status' === $column_name ) {
+
+ // Get TFA info.
+ $tfa = $this->getTFA();
+
+ if( ! $tfa->isActivatedForUser( $user_id ) ) {
+ $value = '&#8212;';
+ }
+ // Use value.
+ elseif ( $tfa->isActivatedByUser( $user_id ) ) {
+ $value = '<span title="' . __( 'Enabled', 'two-factor-authentication' ) . '" class="dashicons dashicons-yes"></span>';
+ }
+ // No group.
+ else {
+ $value = '<span title="' . __( 'Disabled', 'two-factor-authentication' ) . '" class="dashicons dashicons-no"></span>';
+ }
+ }
+
+ // Return possibly modified value.
+ return $value;
+ }
}
$simba_two_factor_authentication = new Simba_Two_Factor_Authentication();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.