<?php
/**
 * Name: Disable Admin Bar (Frontend)
 * Description: Hide the WordPress admin bar on website frontend for all users to provide cleaner visitor experience and remove distracting admin toolbar from public pages
 * Category: Admin
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "Clean Client Previews",
 *     "description": "Remove admin bar from frontend so clients viewing their site while logged in see the true visitor experience without distractions."
 *   },
 *   {
 *     "title": "Screenshot-Ready Sites",
 *     "description": "Disable admin toolbar for marketing team members who take screenshots for social media and don't want the bar visible."
 *   },
 *   {
 *     "title": "Theme Development Testing",
 *     "description": "Hide admin bar while testing responsive designs to see actual header behavior without 32px offset interference."
 *   }
 * ]
 * Added: 2025-06-25
 * Tags: admin-bar, toolbar, frontend, hide, clean
 * WhereToFind: {
 *   "location": "Frontend (Any Page)",
 *   "url": "/",
 *   "instructions": "Admin bar will be hidden at top of frontend pages when logged in",
 *   "newTab": true
 * }
 */

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

class SwitchboardDisableAdminBarFrontend {

    public function __construct() {
        add_filter('show_admin_bar', '__return_false');
    }

    /**
     * Render settings panel
     *
     * @param array $settings Current module settings
     * @return void Outputs HTML directly
     */
    public function render_settings($settings = []) {
        ?>
        <input type="hidden" name="module" value="disable-admin-bar-frontend">

        <?php
        // Check if the role-based "Hide Admin Bar (By Role)" module is active
        $active_modules = get_option('switchboard_active_modules', []);
        if (in_array('hide-admin-bar-roles', $active_modules, true)) : ?>
            <div class="sb-sp-alert sb-sp-alert-info">
                <strong><?php esc_html_e('Note:', 'wpswitchboard'); ?></strong>
                <?php esc_html_e('The "Hide Admin Bar (By Role)" module is also active. This module hides the admin bar for ALL users, so the role-based module will have no additional effect.', 'wpswitchboard'); ?>
            </div>
        <?php endif; ?>

        <p class="sb-sp-description"><?php esc_html_e('This module hides the WordPress admin bar on the frontend for all logged-in users.', 'wpswitchboard'); ?></p>
        <p class="sb-sp-description"><?php esc_html_e('If you want to hide the admin bar only for specific user roles, use the "Hide Admin Bar (By Role)" module instead.', 'wpswitchboard'); ?></p>
        <?php
    }

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

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