<?php
/**
 * Name: Username Body Classes
 * Description: Add current username and user ID as CSS classes to body tag for user-specific styling allowing personalized designs or custom CSS per user
 * Category: Content
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "VIP User Experience",
 *     "description": "Add special styling or show exclusive offers to specific high-value clients identified by username in body class."
 *   },
 *   {
 *     "title": "Beta Tester Access",
 *     "description": "Show new features only to specific beta tester usernames for controlled feature rollout testing."
 *   },
 *   {
 *     "title": "Per-User Customization",
 *     "description": "Apply user-specific CSS for enterprise clients who each need slightly different branded experience."
 *   }
 * ]
 * Added: 2025-09-18
 * Tags: css, body-class, username, styling, frontend
 * WhereToFind: {
 *   "location": "Works automatically site-wide",
 *   "url": "",
 *   "instructions": "Username classes appear in body tag automatically",
 *   "newTab": false
 * }
 */

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

class SwitchboardUsernameBodyClass {

    public function __construct() {
        add_filter('body_class', [$this, 'add_username_class']);
        add_filter('admin_body_class', [$this, 'add_admin_username_class']);
    }

    /**
     * Register data locations for cleanup system
     */
    public function register_data_locations() {
        return [
            'options' => [],
            'option_patterns' => [],
            'tables' => [],
            'post_meta' => [],
            'user_meta' => [],
        ];
    }
    
    public function add_username_class($classes) {
        if (is_user_logged_in()) {
            $user = wp_get_current_user();
            $classes[] = 'user-' . sanitize_html_class($user->user_login);
            $classes[] = 'user-id-' . $user->ID;
        }
        return $classes;
    }
    
    public function add_admin_username_class($classes) {
        if (is_user_logged_in()) {
            $user = wp_get_current_user();
            $classes .= ' user-' . sanitize_html_class($user->user_login);
            $classes .= ' user-id-' . $user->ID;
        }
        return $classes;
    }
}

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