tigerstyle-whiskers/admin/class-admin.php
Ryan Malloy adbdae19c8 Initial commit: TigerStyle Whiskers v1.0.0
Navigate privacy laws with feline precision — detect every boundary,
respect every territory! GDPR compliance and privacy protection for
WordPress.

- Cookie consent management
- Privacy boundary detection
- GDPR-compliant analytics gating
- Cross-plugin consent coordination (integrates with TigerStyle Heat)
- Visitor preference tracking
- Configurable cookie categories

Includes build.sh and .distignore for WordPress-installable release ZIPs.
2026-05-27 14:31:51 -06:00

422 lines
14 KiB
PHP

<?php
/**
* TigerStyle Whiskers Admin Controller
*
* Navigate privacy administration with feline precision - every boundary has its interface!
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
class TigerStyleWhiskers_Admin {
/**
* Single instance
*/
private static $instance = null;
/**
* Admin pages
*/
private $admin_pages = array();
/**
* Get instance
*/
public static function instance() {
if (is_null(self::$instance)) {
self::$instance = new self();
}
return self::$instance;
}
/**
* Constructor
*/
private function __construct() {
$this->init_admin();
}
/**
* Initialize admin components
*/
private function init_admin() {
// Admin menu and pages
add_action('admin_menu', array($this, 'register_admin_menu'));
add_action('admin_init', array($this, 'admin_init'));
add_action('admin_enqueue_scripts', array($this, 'enqueue_admin_assets'));
// AJAX handlers for privacy requests
add_action('wp_ajax_whiskers_handle_data_request', array($this, 'handle_data_request'));
add_action('wp_ajax_whiskers_run_cookie_scan', array($this, 'run_cookie_scan'));
add_action('wp_ajax_whiskers_update_compliance', array($this, 'update_compliance_settings'));
add_action('wp_ajax_tigerstyle_whiskers_save_inventory_completion', array($this, 'save_inventory_completion'));
add_action('wp_ajax_tigerstyle_whiskers_schedule_review', array($this, 'schedule_compliance_review'));
// Admin notices
add_action('admin_notices', array($this, 'display_admin_notices'));
// Initialize admin pages controller
TigerStyleWhiskers_Admin_Pages::instance();
}
/**
* Register admin menu and pages
*/
public function register_admin_menu() {
// Main Whiskers page
add_menu_page(
__('TigerStyle Whiskers', 'tigerstyle-whiskers'),
__('Whiskers', 'tigerstyle-whiskers'),
'manage_options',
'tigerstyle-whiskers',
array($this, 'render_main_page'),
'data:image/svg+xml;base64,' . base64_encode($this->get_menu_icon()),
30
);
// Dashboard submenu
add_submenu_page(
'tigerstyle-whiskers',
__('Privacy Dashboard', 'tigerstyle-whiskers'),
__('📊 Dashboard', 'tigerstyle-whiskers'),
'manage_options',
'tigerstyle-whiskers',
array($this, 'render_main_page')
);
// Consent Analytics
add_submenu_page(
'tigerstyle-whiskers',
__('Consent Analytics', 'tigerstyle-whiskers'),
__('📈 Consent Analytics', 'tigerstyle-whiskers'),
'manage_options',
'whiskers-consent-analytics',
array($this, 'render_consent_analytics')
);
// Data Requests
add_submenu_page(
'tigerstyle-whiskers',
__('Data Requests', 'tigerstyle-whiskers'),
__('📋 Data Requests', 'tigerstyle-whiskers'),
'manage_options',
'whiskers-data-requests',
array($this, 'render_data_requests')
);
// Cookie Scanner
add_submenu_page(
'tigerstyle-whiskers',
__('Cookie Scanner', 'tigerstyle-whiskers'),
__('🍪 Cookie Scanner', 'tigerstyle-whiskers'),
'manage_options',
'whiskers-cookie-scanner',
array($this, 'render_cookie_scanner')
);
// Compliance Monitor
add_submenu_page(
'tigerstyle-whiskers',
__('Compliance Monitor', 'tigerstyle-whiskers'),
__('✅ Compliance', 'tigerstyle-whiskers'),
'manage_options',
'whiskers-compliance',
array($this, 'render_compliance_monitor')
);
// Settings
add_submenu_page(
'tigerstyle-whiskers',
__('Whiskers Settings', 'tigerstyle-whiskers'),
__('⚙️ Settings', 'tigerstyle-whiskers'),
'manage_options',
'whiskers-settings',
array($this, 'render_settings')
);
}
/**
* Get SVG menu icon
*/
private function get_menu_icon() {
return '<svg viewBox="0 0 24 24" fill="currentColor">
<path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm-1 17.93c-3.94-.49-7-3.85-7-7.93 0-.62.08-1.21.21-1.79L9 15v1c0 1.1.9 2 2 2v1.93zm6.9-2.54c-.26-.81-1-1.39-1.9-1.39h-1v-3c0-.55-.45-1-1-1H8v-2h2c.55 0 1-.45 1-1V7h2c1.1 0 2-.9 2-2v-.41c2.93 1.19 5 4.06 5 7.41 0 2.08-.8 3.97-2.1 5.39z"/>
<!-- Cat whiskers -->
<line x1="3" y1="10" x2="6" y2="9.5" stroke="currentColor" stroke-width="0.5"/>
<line x1="3" y1="12" x2="6" y2="12" stroke="currentColor" stroke-width="0.5"/>
<line x1="3" y1="14" x2="6" y2="14.5" stroke="currentColor" stroke-width="0.5"/>
<line x1="21" y1="10" x2="18" y2="9.5" stroke="currentColor" stroke-width="0.5"/>
<line x1="21" y1="12" x2="18" y2="12" stroke="currentColor" stroke-width="0.5"/>
<line x1="21" y1="14" x2="18" y2="14.5" stroke="currentColor" stroke-width="0.5"/>
</svg>';
}
/**
* Admin initialization
*/
public function admin_init() {
// Register settings
register_setting('whiskers_settings', 'whiskers_options');
// Initialize admin notices
$this->check_heat_integration();
}
/**
* Enqueue admin assets
*/
public function enqueue_admin_assets($hook) {
// Only load on Whiskers admin pages
if (strpos($hook, 'whiskers') === false && strpos($hook, 'tigerstyle-whiskers') === false) {
return;
}
// Admin CSS
wp_enqueue_style(
'whiskers-admin',
TIGERSTYLE_WHISKERS_PLUGIN_URL . 'assets/css/admin.css',
array(),
TIGERSTYLE_WHISKERS_VERSION
);
// Admin JavaScript
wp_enqueue_script(
'whiskers-admin',
TIGERSTYLE_WHISKERS_PLUGIN_URL . 'assets/js/admin.js',
array('jquery', 'wp-api'),
TIGERSTYLE_WHISKERS_VERSION,
true
);
// Chart.js for analytics
wp_enqueue_script(
'chartjs',
'https://cdn.jsdelivr.net/npm/chart.js',
array(),
'3.9.1',
true
);
// Localize script for AJAX
wp_localize_script('whiskers-admin', 'whiskersAdmin', array(
'ajaxurl' => admin_url('admin-ajax.php'),
'nonce' => wp_create_nonce('whiskers_admin_nonce'),
'strings' => array(
'cookieScanInProgress' => __('Scanning cookies with feline precision...', 'tigerstyle-whiskers'),
'complianceCheckRunning' => __('Checking compliance boundaries...', 'tigerstyle-whiskers'),
'dataRequestProcessed' => __('Data request processed successfully!', 'tigerstyle-whiskers'),
'errorOccurred' => __('An error occurred. Please check your whiskers and try again.', 'tigerstyle-whiskers'),
)
));
}
/**
* Check Heat integration status
*/
private function check_heat_integration() {
if (class_exists('TigerStyleSEO')) {
update_option('whiskers_heat_integration', 'active');
} else {
update_option('whiskers_heat_integration', 'missing');
}
}
/**
* Display admin notices
*/
public function display_admin_notices() {
$heat_integration = get_option('whiskers_heat_integration', 'unknown');
if ($heat_integration === 'missing') {
echo '<div class="notice notice-info is-dismissible">';
echo '<p><strong>🐱 TigerStyle Whiskers:</strong> ';
echo __('Install TigerStyle Heat for enhanced SEO-privacy integration!', 'tigerstyle-whiskers');
echo '</p>';
echo '</div>';
} elseif ($heat_integration === 'active') {
echo '<div class="notice notice-success is-dismissible">';
echo '<p><strong>🔥🐱 Integration Active:</strong> ';
echo __('Heat respects Whiskers consent boundaries perfectly!', 'tigerstyle-whiskers');
echo '</p>';
echo '</div>';
}
}
/**
* Render main dashboard page
*/
public function render_main_page() {
TigerStyleWhiskers_Admin_Pages::render_dashboard();
}
/**
* Render consent analytics page
*/
public function render_consent_analytics() {
TigerStyleWhiskers_Admin_Pages::render_consent_analytics();
}
/**
* Render data requests page
*/
public function render_data_requests() {
TigerStyleWhiskers_Admin_Pages::render_data_requests();
}
/**
* Render cookie scanner page
*/
public function render_cookie_scanner() {
TigerStyleWhiskers_Admin_Pages::render_cookie_scanner();
}
/**
* Render compliance monitor page
*/
public function render_compliance_monitor() {
TigerStyleWhiskers_Admin_Pages::render_compliance_monitor();
}
/**
* Render settings page
*/
public function render_settings() {
TigerStyleWhiskers_Admin_Pages::render_settings();
}
/**
* AJAX: Handle data request
*/
public function handle_data_request() {
check_ajax_referer('whiskers_admin_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_die(__('Insufficient permissions', 'tigerstyle-whiskers'));
}
$request_type = sanitize_text_field($_POST['request_type']);
$email = sanitize_email($_POST['email']);
// Process through data deletion whisker
$data_deletion = tigerstyle_whiskers()->get_whisker('data_deletion');
if ($data_deletion) {
$result = $data_deletion->process_request($request_type, $email);
wp_send_json_success($result);
} else {
wp_send_json_error(__('Data deletion whisker not available', 'tigerstyle-whiskers'));
}
}
/**
* AJAX: Run cookie scan
*/
public function run_cookie_scan() {
check_ajax_referer('whiskers_admin_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_die(__('Insufficient permissions', 'tigerstyle-whiskers'));
}
// Simulate cookie scanning (would integrate with actual scanner)
sleep(2); // Simulate scanning time
$cookies = array(
'necessary' => array('wordpress_test_cookie', 'PHPSESSID'),
'analytics' => array('_ga', '_gid', '_gat'),
'marketing' => array('_fbp', 'tr'),
'preferences' => array('wp-settings-1'),
);
wp_send_json_success(array(
'message' => __('Cookie scan completed with feline precision!', 'tigerstyle-whiskers'),
'cookies' => $cookies,
'total' => array_sum(array_map('count', $cookies))
));
}
/**
* AJAX: Update compliance settings
*/
public function update_compliance_settings() {
check_ajax_referer('whiskers_admin_nonce', 'nonce');
if (!current_user_can('manage_options')) {
wp_die(__('Insufficient permissions', 'tigerstyle-whiskers'));
}
$settings = $_POST['settings'];
// Sanitize and update settings
$sanitized_settings = array();
foreach ($settings as $key => $value) {
$sanitized_settings[sanitize_key($key)] = sanitize_text_field($value);
}
update_option('whiskers_compliance_settings', $sanitized_settings);
wp_send_json_success(array(
'message' => __('Compliance settings updated successfully!', 'tigerstyle-whiskers')
));
}
/**
* Save data inventory completion status
*/
public function save_inventory_completion() {
// Verify nonce
if (!wp_verify_nonce($_POST['nonce'], 'tigerstyle_whiskers_ajax')) {
wp_die('Security check failed', 'Error', array('response' => 403));
}
// Update option to mark inventory as completed
update_option('tigerstyle_whiskers_data_inventory_completed', true);
wp_send_json_success(array(
'message' => 'Data inventory completion saved successfully'
));
}
/**
* Schedule compliance review
*/
public function schedule_compliance_review() {
// Verify nonce
if (!wp_verify_nonce($_POST['nonce'], 'whiskers_admin_nonce')) {
wp_die('Security check failed', 'Error', array('response' => 403));
}
// Calculate next quarterly review date (3 months from now)
$next_review_date = date('Y-m-d H:i:s', strtotime('+3 months'));
// Get existing scheduled reviews
$scheduled_reviews = get_option('tigerstyle_whiskers_scheduled_reviews', array());
// Add new review to the schedule
$new_review = array(
'id' => uniqid(),
'type' => 'quarterly_compliance',
'scheduled_date' => $next_review_date,
'status' => 'scheduled',
'created_date' => current_time('mysql'),
'created_by' => get_current_user_id(),
'description' => 'Quarterly compliance review for multi-jurisdiction privacy regulations'
);
$scheduled_reviews[] = $new_review;
// Save updated schedule
update_option('tigerstyle_whiskers_scheduled_reviews', $scheduled_reviews);
// Also set a flag that reviews are scheduled
update_option('tigerstyle_whiskers_reviews_scheduled', true);
wp_send_json_success(array(
'message' => 'Compliance review scheduled successfully',
'next_review_date' => $next_review_date,
'formatted_date' => date('F j, Y', strtotime($next_review_date))
));
}
}