<?php
/**
 * Name: Clean WP Dashboard
 * Description: Remove unnecessary WordPress dashboard widgets and clutter including welcome panel, WordPress events and news, and other default widgets to create clean interface
 * Category: Admin
 * Icon: -
 * UseCases: [
 *   {
 *     "title": "Client-Ready Dashboard",
 *     "description": "Remove WordPress news, Quick Draft, and other clutter widgets to present a clean, professional dashboard focused only on site-specific metrics."
 *   },
 *   {
 *     "title": "Performance Focused Setup",
 *     "description": "Strip all unnecessary dashboard widgets from high-traffic sites to reduce admin load time and improve backend performance."
 *   },
 *   {
 *     "title": "Distraction-Free Writing Environment",
 *     "description": "Remove promotional content and news feeds for bloggers and writers who want to focus only on their content creation."
 *   }
 * ]
 * Added: 2025-07-05
 * Tags: dashboard, widgets, clean, minimal, admin, declutter
 * WhereToFind: {
 *   "location": "Dashboard",
 *   "url": "admin.php",
 *   "instructions": "Dashboard widgets will be removed based on your selection",
 *   "newTab": false
 * }
 */

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

class SwitchboardCleanDashboard {

    public function __construct() {
        add_action('wp_dashboard_setup', [$this, 'remove_dashboard_widgets']);
        add_action('admin_init', [$this, 'remove_welcome_panel']);
    }

    public function remove_dashboard_widgets() {
        // Remove default dashboard widgets
        remove_meta_box('dashboard_incoming_links', 'dashboard', 'normal');
        remove_meta_box('dashboard_plugins', 'dashboard', 'normal');
        remove_meta_box('dashboard_primary', 'dashboard', 'side');
        remove_meta_box('dashboard_secondary', 'dashboard', 'normal');
        remove_meta_box('dashboard_quick_press', 'dashboard', 'side');
        remove_meta_box('dashboard_recent_drafts', 'dashboard', 'side');
        remove_meta_box('dashboard_recent_comments', 'dashboard', 'normal');
        remove_meta_box('dashboard_right_now', 'dashboard', 'normal');
        remove_meta_box('dashboard_activity', 'dashboard', 'normal');
    }

    public function remove_welcome_panel() {
        remove_action('welcome_panel', 'wp_welcome_panel');
    }

    /**
     * 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="clean-dashboard">

        <?php
        // Check if the selective "Disable Dashboard Widgets (Selective)" module is active
        $active_modules = get_option('switchboard_active_modules', []);
        if (in_array('disable-dashboard-widgets-select', $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 "Disable Dashboard Widgets (Selective)" module is also active. This module removes ALL widgets, so the selective module will have no additional effect.', 'wpswitchboard'); ?>
            </div>
        <?php endif; ?>

        <p class="sb-sp-description"><?php esc_html_e('This module removes all default WordPress dashboard widgets including At a Glance, Activity, Quick Draft, WordPress Events and News, and the Welcome Panel.', 'wpswitchboard'); ?></p>
        <p class="sb-sp-description"><?php esc_html_e('If you want to selectively choose which widgets to hide, use the "Disable Dashboard Widgets (Selective)" 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 SwitchboardCleanDashboard();
Switchboard_Data_Registry::get_instance()->auto_register($switchboard_instance, __FILE__);