← Back
Editing: class-admin.php
<?php defined( 'ABSPATH' ) || exit; class ADM_Alt_Admin { public static function init() { add_action( 'admin_menu', [ __CLASS__, 'register_menu' ] ); add_action( 'admin_enqueue_scripts', [ __CLASS__, 'enqueue_assets' ] ); add_action( 'admin_post_adm_alt_save_settings', [ __CLASS__, 'save_settings' ] ); add_action( 'admin_post_adm_alt_rollback', [ __CLASS__, 'rollback_all' ] ); add_action( 'admin_post_adm_alt_clear_logs', [ __CLASS__, 'clear_logs' ] ); add_action( 'admin_post_adm_alt_export_csv', [ __CLASS__, 'export_csv' ] ); add_action( 'admin_notices', [ __CLASS__, 'activation_redirect' ] ); } public static function register_menu() { add_menu_page( 'All-in-One Image Intelligence by ADM', 'Image Intelligence', 'manage_options', 'adm-alt-automator', [ __CLASS__, 'page_dashboard' ], 'dashicons-camera-alt', 80 ); add_submenu_page( 'adm-alt-automator', 'Dashboard', 'Dashboard', 'manage_options', 'adm-alt-automator', [ __CLASS__, 'page_dashboard' ] ); add_submenu_page( 'adm-alt-automator', 'Audit Log', 'Audit Log', 'manage_options', 'adm-alt-audit', [ __CLASS__, 'page_audit' ] ); add_submenu_page( 'adm-alt-automator', 'Settings', 'Settings', 'manage_options', 'adm-alt-settings', [ __CLASS__, 'page_settings' ] ); } public static function enqueue_assets( string $hook ) { if ( strpos( $hook, 'adm-alt' ) === false ) return; wp_enqueue_style( 'adm-alt-css', ADM_ALT_URL . 'admin/css/admin.css', [], ADM_ALT_VERSION ); wp_enqueue_script( 'adm-alt-js', ADM_ALT_URL . 'admin/js/admin.js', [], ADM_ALT_VERSION, true ); wp_localize_script( 'adm-alt-js', 'admAlt', [ 'ajaxUrl' => admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'adm_alt_nonce' ), 'auditUrl' => admin_url( 'admin.php?page=adm-alt-audit' ), 'settingsUrl' => admin_url( 'admin.php?page=adm-alt-settings' ), ] ); } public static function activation_redirect() { if ( get_transient( 'adm_alt_activated' ) ) { delete_transient( 'adm_alt_activated' ); // Send to Settings first so location can be configured before scanning wp_safe_redirect( admin_url( 'admin.php?page=adm-alt-settings' ) ); exit; } } public static function page_dashboard() { require ADM_ALT_DIR . 'admin/views/dashboard.php'; } public static function page_audit() { require ADM_ALT_DIR . 'admin/views/audit.php'; } public static function page_settings() { require ADM_ALT_DIR . 'admin/views/settings.php'; } // ── Save Settings ───────────────────────────────────────────────────────── public static function save_settings() { check_admin_referer( 'adm_alt_save_settings' ); if ( ! current_user_can( 'manage_options' ) ) wp_die( 'Forbidden' ); // Claude API key update_option( 'adm_alt_claude_key', sanitize_text_field( wp_unslash( $_POST['adm_claude_key'] ?? '' ) ) ); // Location $name = sanitize_text_field( wp_unslash( $_POST['adm_practice_name'] ?? '' ) ); $site = esc_url_raw( wp_unslash( $_POST['adm_website'] ?? '' ) ); $addr = sanitize_text_field( wp_unslash( $_POST['adm_address'] ?? '' ) ); $lat = sanitize_text_field( wp_unslash( $_POST['adm_lat'] ?? '' ) ); $lng = sanitize_text_field( wp_unslash( $_POST['adm_lng'] ?? '' ) ); update_option( 'adm_alt_business_name', $name ); update_option( 'adm_alt_business_website', $site ); update_option( 'adm_alt_business_address', $addr ); update_option( 'adm_alt_gps_lat', $lat ); update_option( 'adm_alt_gps_lng', $lng ); // Store in unified format used by processor and geocoder if ( $lat !== '' && $lng !== '' ) { update_option( 'adm_alt_gps_coords', [ 'lat' => (float) $lat, 'lng' => (float) $lng, 'address' => $addr ?: $name, ] ); } else { delete_option( 'adm_alt_gps_coords' ); } wp_safe_redirect( admin_url( 'admin.php?page=adm-alt-settings&saved=1' ) ); exit; } // ── Other actions ───────────────────────────────────────────────────────── public static function rollback_all() { check_admin_referer( 'adm_alt_rollback' ); if ( ! current_user_can( 'manage_options' ) ) wp_die( 'Forbidden' ); ADM_Alt_DB_Handler::rollback_all(); wp_safe_redirect( admin_url( 'admin.php?page=adm-alt-automator&rolled_back=1' ) ); exit; } public static function clear_logs() { check_admin_referer( 'adm_alt_clear_logs' ); if ( ! current_user_can( 'manage_options' ) ) wp_die( 'Forbidden' ); ADM_Alt_DB_Handler::clear_logs(); wp_safe_redirect( admin_url( 'admin.php?page=adm-alt-audit&cleared=1' ) ); exit; } public static function export_csv() { check_admin_referer( 'adm_alt_export_csv' ); if ( ! current_user_can( 'manage_options' ) ) wp_die( 'Forbidden' ); $logs = ADM_Alt_DB_Handler::get_logs( 9999 ); header( 'Content-Type: text/csv; charset=utf-8' ); header( 'Content-Disposition: attachment; filename="alt-text-audit-' . date( 'Y-m-d' ) . '.csv"' ); $out = fopen( 'php://output', 'w' ); fputcsv( $out, [ 'ID', 'Image URL', 'Page', 'Old Alt', 'New Alt', 'Status', 'GPS Written', 'GPS Error', 'Error', 'Date' ] ); foreach ( $logs as $row ) { fputcsv( $out, [ $row['id'], $row['image_url'], $row['page_title'], $row['old_alt'], $row['new_alt'], $row['status'], $row['gps_written'] ? 'Yes' : 'No', $row['gps_error'] ?? '', $row['error_msg'] ?? '', $row['created_at'], ] ); } fclose( $out ); exit; } public static function location_configured(): bool { return ( get_option( 'adm_alt_gps_lat', '' ) !== '' && get_option( 'adm_alt_gps_lng', '' ) !== '' ); } }
Save File
Cancel