[ column key, default ]. Every column is * opt-in, like every other setting on a fresh install. * * @var array */ private const COLUMNS = array( 'col_user_id' => array( Columns::COL_ID, 0 ), 'col_registered' => array( Columns::COL_REGISTERED, 0 ), 'col_age' => array( Columns::COL_AGE, 0 ), 'col_last_login' => array( Columns::COL_LAST_LOGIN, 0 ), ); /** * {@inheritDoc} */ public function get_id(): string { return 'user_management'; } /** * {@inheritDoc} */ public function register(): void { $settings = aiou()->settings(); $this->register_settings( $settings ); if ( ! $settings->get_value( self::TAB, self::SECTION, 'enabled', 0 ) ) { return; } ( new LoginTracker() )->register(); $enabled = array(); foreach ( self::COLUMNS as $field_id => $column ) { if ( $settings->get_value( self::TAB, self::SECTION, $field_id, $column[1] ) ) { $enabled[] = $column[0]; } } ( new Columns( $enabled ) )->register(); } /** * Register the "Users Screen" section and its fields. * * @param SettingsRegistry $settings The settings registry. * @return void */ private function register_settings( SettingsRegistry $settings ): void { $settings->add_section( self::TAB, self::SECTION, __( 'Users Screen', 'all-in-one-utilities' ), __( 'Add useful columns to Users → All Users and track when each user last logged in.', 'all-in-one-utilities' ), 40 ); $settings->add_field( self::TAB, self::SECTION, new Field( id: 'enabled', label: __( 'Enhance the Users screen', 'all-in-one-utilities' ), type: 'checkbox', default: 0, args: array( 'toggle_label' => __( 'Add extra columns and track successful logins', 'all-in-one-utilities' ) ), doc: new Doc( title: __( 'Users screen enhancements', 'all-in-one-utilities' ), short: __( 'Extends the native Users → All Users table with extra columns; nothing about the screen is replaced.', 'all-in-one-utilities' ), detailed: __( 'While this is on, every successful login records the user\'s last login time and login count. WordPress itself stores neither, so tracking starts the moment this is first switched on -- users who haven\'t logged in since then show "Not recorded" rather than "Never".', 'all-in-one-utilities' ), warnings: array( __( 'Turning this off stops recording new logins. Data already recorded is kept.', 'all-in-one-utilities' ) ) ), priority: 10 ) ); $columns = array( 'col_user_id' => array( __( 'User ID column', 'all-in-one-utilities' ), __( 'Show each user\'s numeric WordPress ID', 'all-in-one-utilities' ) ), 'col_registered' => array( __( 'Registered column', 'all-in-one-utilities' ), __( 'Show the date each user registered', 'all-in-one-utilities' ) ), 'col_age' => array( __( 'Account Age column', 'all-in-one-utilities' ), __( 'Show how long each account has existed', 'all-in-one-utilities' ) ), 'col_last_login' => array( __( 'Last Login column', 'all-in-one-utilities' ), __( 'Show each user\'s most recent successful login', 'all-in-one-utilities' ) ), ); $priority = 20; foreach ( $columns as $id => $labels ) { $settings->add_field( self::TAB, self::SECTION, new Field( id: $id, label: $labels[0], type: 'checkbox', default: self::COLUMNS[ $id ][1], args: array( 'toggle_label' => $labels[1], 'depends_on' => 'enabled', ), priority: $priority ) ); $priority += 10; } } }