SettingsPage.php
5 years ago
SetupWizard.php
5 years ago
UserListing.php
5 years ago
UserNotices.php
5 years ago
UserProfile.php
5 years ago
UserRegistered.php
5 years ago
UserListing.php
80 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WP2FA\Admin; |
| 4 | |
| 5 | use WP2FA\Utils\UserUtils; |
| 6 | |
| 7 | defined( 'ABSPATH' ) || exit; // Exit if accessed directly |
| 8 | |
| 9 | /** |
| 10 | * UserListing class with user listing filters |
| 11 | */ |
| 12 | if ( ! class_exists( '\WP2FA\Admin\UserListing' ) ) { |
| 13 | |
| 14 | /** |
| 15 | * UserListing - Shows extra column in user table wit WP2FA status forevery user |
| 16 | */ |
| 17 | class UserListing { |
| 18 | |
| 19 | /** |
| 20 | * The users table column name |
| 21 | * |
| 22 | * @var string |
| 23 | */ |
| 24 | private static $columnName = '2fa-status'; |
| 25 | |
| 26 | /** |
| 27 | * Inits all the hooks used for showing the extra user data in the users column |
| 28 | * |
| 29 | * @return void |
| 30 | */ |
| 31 | public static function init() { |
| 32 | add_filter( 'manage_users_columns', [ __CLASS__, 'addWP2FAColumn' ] ); |
| 33 | add_filter( 'wpmu_users_columns', [ __CLASS__, 'addWP2FAColumn' ] ); |
| 34 | add_filter( 'manage_users_custom_column', [ __CLASS__, 'showColumnData' ], 10, 3 ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Sets the column in the admin users table |
| 39 | * |
| 40 | * @param array $columns |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | public static function addWP2FAColumn( array $columns ): array { |
| 45 | $columns[ self::$columnName ] = __( '2FA Status', 'wp-2fa' ); |
| 46 | return $columns; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Shows the user WP 2FA status data in the users table |
| 51 | * |
| 52 | * @param [type] $value |
| 53 | * @param string $columnName |
| 54 | * @param [type] $userId |
| 55 | * |
| 56 | * @return mixed |
| 57 | */ |
| 58 | public static function showColumnData( $value, string $columnName, $userId ) { |
| 59 | |
| 60 | switch ( $columnName ) { |
| 61 | case self::$columnName: |
| 62 | $faStatuses = UserUtils::determine_user_2fa_status( new \WP_User( $userId ) ); |
| 63 | return UserUtils::extractStatuses( $faStatuses ); |
| 64 | default: |
| 65 | } |
| 66 | |
| 67 | return $value; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Returns the users table column name |
| 72 | * |
| 73 | * @return string |
| 74 | */ |
| 75 | public static function getColumnName(): string { |
| 76 | return self::$columnName; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 |