<?php
/**
 * Name: Registration Date Column
 * Description: Add registration date column to users list table showing when each user account was created for tracking growth, auditing accounts, and identifying old users
 * Category: User Management
 * Icon: -
  * UseCases: [
 *   {
 *     "title": "Track User Growth",
 *     "description": "See when users signed up to analyze registration patterns and measure the success of marketing campaigns."
 *   },
 *   {
 *     "title": "Sort by Recency",
 *     "description": "Quickly find and welcome new members by sorting users by their registration date."
 *   }
 * ]
 * Added: 2025-07-18
 * Tags: users, registration, date, admin, columns
 * WhereToFind: {
 *   "location": "Users List",
 *   "url": "users.php",
 *   "instructions": "'Registered' column appears with registration dates",
 *   "newTab": false
 * }
 */

// Prevent direct access
if (!defined('ABSPATH')) exit;

class SwitchboardRegistrationDateColumn {
    
    public function __construct() {
        add_filter('manage_users_columns', [$this, 'add_column']);
        add_filter('manage_users_custom_column', [$this, 'show_column'], 10, 3);
        add_filter('manage_users_sortable_columns', [$this, 'sortable_column']);
    }
    
    public function add_column($columns) {
        $columns['registration_date'] = __('Registered', 'wpswitchboard');
        return $columns;
    }
    
    public function show_column($value, $column_name, $user_id) {
        if ($column_name === 'registration_date') {
            $user = get_userdata($user_id);
            return wp_date('Y-m-d', strtotime($user->user_registered));
        }
        return $value;
    }
    
    public function sortable_column($columns) {
        $columns['registration_date'] = 'registered';
        return $columns;
    }

    /**
     * Register data locations for cleanup system
     */
    public function register_data_locations() {
        return [
            'options' => [],
            'option_patterns' => [],
            'tables' => [],
            'post_meta' => [],
            'user_meta' => [],
        ];
    }
}

$switchboard_instance = new SwitchboardRegistrationDateColumn();
Switchboard_Data_Registry::get_instance()->auto_register($switchboard_instance, __FILE__);
