# Dead Code Audit - translate-press-zone Plugin

Audit date: 2026-03-14
Scope: `/home/user/Projects/Press.zone/wordpress/wp-content/plugins/translate-press-zone/`

---

## 1. Dead/Unused PHP Classes (entire files)

### `includes/class-tpz-errorcodes.php` (ErrorCodes class)
- **Line:** 16
- **What:** `TranslatePresszone\ErrorCodes` class with 30+ constants and 6 static methods
- **Why dead:** Never instantiated or referenced anywhere in the codebase. No other file uses `ErrorCodes::`, `use TranslatePresszone\ErrorCodes`, or any of its constants. The autoloader would load it if referenced, but nothing references it.

### `includes/class-tpz-ratelimiter.php` (RateLimiter class)
- **Line:** 16
- **What:** `TranslatePresszone\RateLimiter` class with sliding-window rate limiting
- **Why dead:** Never instantiated anywhere. No `new RateLimiter`, no `use TranslatePresszone\RateLimiter`, no references to `check_rate_limit()` outside its own file.

### `includes/class-tpz-queryoptimizer.php` (QueryOptimizer class)
- **Line:** 15
- **What:** `TranslatePresszone\QueryOptimizer` class for read-replica routing
- **Why dead:** Declared as `private QueryOptimizer $query_optimizer` in Plugin (line 37) but **never instantiated**. The property is never assigned. No code calls any of its methods (`get_results`, `get_row`, `get_var`, `has_read_replica`).

---

## 2. Dead/Unused PHP Methods

### `Plugin::get_logger()` - `includes/class-tpz-plugin.php:216`
- **What:** Public getter for the logger instance
- **Why dead:** Never called from any other file. All consumers create their own `new Logger()` instance.

### `Plugin::admin_init()` - `includes/class-tpz-plugin.php:186`
- **What:** Admin initialization hook callback
- **Why dead:** Registered via `add_action('admin_init', ...)` but the method body is empty (just a comment placeholder). The hook fires but does nothing.

### `Admin::render_settings_page()` - `admin/class-tpz-admin.php:194`
- **What:** Server-rendered settings page (includes settings-page.php view)
- **Why dead:** Never registered as a page callback. The SPA's `render_app()` replaced it. The method exists but nothing calls it or registers it as a menu callback.

### `Admin::render_jobs_page()` - `admin/class-tpz-admin.php:351`
- **What:** Server-rendered jobs page (includes jobs-page.php view)
- **Why dead:** Same as above -- never registered as a menu callback. Orphaned legacy method.

### `Admin::fetch_translation_jobs()` - `admin/class-tpz-admin.php:366`
- **What:** Fetches translation jobs from API for the legacy jobs page
- **Why dead:** Only called by `render_jobs_page()` which itself is dead.

### `Settings::regenerate_callback_secret()` - `includes/class-tpz-settings.php:243`
- **What:** Regenerates the HMAC callback secret
- **Why dead:** Never called anywhere. No REST endpoint, no admin action, no hook calls it.

### `Settings::clear_all()` - `includes/class-tpz-settings.php:416`
- **What:** Deletes all plugin options
- **Why dead:** Never called. The `uninstall.php` deletes options directly rather than using this method.

### `PartitionManager::ensure_jobs_partitioning()` - `includes/class-tpz-partitionmanager.php:36`
- **What:** Main method to partition the jobs table
- **Why dead:** `PartitionManager` is instantiated in Plugin (line 140) but the constructor does nothing, and `ensure_jobs_partitioning()` is never called. The entire class is effectively a no-op.

### `PartitionManager::maintenance_partitions()` - `includes/class-tpz-partitionmanager.php:156`
- **What:** Partition maintenance (method body is a stub/placeholder)
- **Why dead:** Only called internally by `ensure_jobs_partitioning()` which is itself never called.

### `Dashboard::get_translatable_post_types()` - `admin/class-tpz-dashboard.php:566`
- **What:** Public wrapper that delegates to `$this->bridge->get_translatable_post_types()`
- **Why dead:** Only called from `admin/views/dashboard-page.php` which is part of the legacy dashboard (Tools menu). The SPA calls the REST API instead. While technically reachable via the legacy dashboard, this is a redundant wrapper.

---

## 3. Orphaned Files

### `admin/js/admin.js`
- **What:** Legacy admin JavaScript for the settings page (API key toggle, verify, test connection)
- **Why dead:** Never enqueued in any PHP file. The `wp_dequeue_script('presszone-translate-admin')` in Admin class (line 134) actively removes it. Replaced by the SPA.

### `admin/js/pricing-fetcher.js`
- **What:** JavaScript class to fetch model pricing from the backend API
- **Why dead:** Never enqueued in any PHP file. No references anywhere.

### `admin/css/dashboard.scss`
- **What:** Standalone SCSS file (not under `src/styles/`)
- **Why dead:** Not imported by any SCSS file, not a webpack entry point, not compiled by the build, not enqueued anywhere.

### `admin/views/settings-page.php`
- **What:** Server-rendered settings page template
- **Why dead:** Only loaded by `Admin::render_settings_page()` which is never called (see dead methods above). The SPA handles settings.

### `admin/views/jobs-page.php`
- **What:** Server-rendered jobs page template
- **Why dead:** Only loaded by `Admin::render_jobs_page()` which is never called.

### `admin/views/widgets/security-alerts.php`
- **What:** Dashboard widget for security alerts
- **Why dead:** Never required/included by any PHP file. No `require_once`, no `include` references to this file.

### `admin/src/pages/posts.js`
- **What:** Standalone Posts page component
- **Why dead:** Never imported by any other JS file. `main.js` routes to `translation.js` (which handles both Posts and Pages tabs). `posts.js` exists as a separate orphaned implementation.

### `admin/src/pages/settings-unified.js`
- **What:** Unified settings page (alternative implementation)
- **Why dead:** Never imported by `main.js` or any other file. `main.js` routes to `settings.js` instead. This file imports components but is never loaded.

### `admin/src/components/test-sortable.js`
- **What:** Test/demo file for the SortableList component
- **Why dead:** Never imported anywhere. Development-only artifact.

### `admin/src/components/LinkSelector.example.js`
- **What:** Example/demo file for LinkSelector component
- **Why dead:** Never imported anywhere. Development-only artifact.

### `admin/src/components/SortableList.example.js`
- **What:** Example/demo file for SortableList component
- **Why dead:** Never imported anywhere. Development-only artifact.

### `_archive/` directory (entire tree)
- **What:** Archived backend application (Modal service, admin panel, API)
- **Why dead:** Not referenced by any plugin code. Contains old Python/Node.js backend code that was moved to `press-zone-backend/`. Should not ship with the plugin.

### `.opencode/` directory
- **What:** OpenCode AI configuration files
- **Why dead:** Development tool configuration, not part of plugin functionality. Should not ship with the plugin.

### `.php-cs-fixer.dist.php`
- **What:** PHP CS Fixer configuration
- **Why dead:** Development tool, not part of plugin runtime. Not harmful but should not ship.

---

## 4. Unused JS Components (exported in index.js but never imported)

### `admin/src/components/AnimatedItem.js`
- **What:** Animation wrapper component
- **Why dead:** Exported from `index.js` but never imported by any page or section.

### `admin/src/components/AssignmentCard.js`
- **What:** Assignment card component (workflow-related)
- **Why dead:** Never imported anywhere outside its own file.

### `admin/src/components/ColorField.js`
- **What:** Color input field component
- **Why dead:** Never imported. Also imports ColorPickerModal which becomes dead by transitivity.

### `admin/src/components/ColorPickerModal.js`
- **What:** Color picker modal component
- **Why dead:** Only imported by `ColorField.js` which is itself unused. Dead by transitivity.

### `admin/src/components/FilterBar.js`
- **What:** Filter bar component
- **Why dead:** Never imported by any page.

### `admin/src/components/FlagPicker.js`
- **What:** Language flag picker component
- **Why dead:** Never imported by any page (SCSS for it exists and is compiled, but the JS component is unused).

### `admin/src/components/GridTable.js`
- **What:** CSS Grid-based table component
- **Why dead:** Never imported. `Table.js` is used instead.

### `admin/src/components/StateTransitionButton.js`
- **What:** Workflow state transition button
- **Why dead:** Never imported by any page.

### `admin/src/components/StatusFeedback.js`
- **What:** Status feedback display component
- **Why dead:** Never imported by any page.

### `admin/src/components/TagInput.js`
- **What:** Tag input component
- **Why dead:** Never imported by any page.

### `admin/src/components/TileSelect.js`
- **What:** Tile-based selection component
- **Why dead:** Never imported by any page.

### `admin/src/components/TranslationProgress.js`
- **What:** Translation progress display component
- **Why dead:** Never imported by any page. (The inline progress tracking in `translation.js` uses its own implementation with ProgressBar.)

### `admin/src/components/WorkflowTimeline.js`
- **What:** Workflow timeline visualization
- **Why dead:** Never imported by any page.

### `admin/src/components/DeadlineIndicator.js`
- **What:** Deadline indicator component
- **Why dead:** Only referenced by `AssignmentCard.js` and `WorkflowTimeline.js`, both of which are themselves unused. Dead by transitivity.

### `admin/src/components/PriorityBadge.js`
- **What:** Priority level badge component
- **Why dead:** Only referenced by `AssignmentCard.js`, `StateTransitionButton.js`, and `WorkflowTimeline.js` -- all of which are unused. Dead by transitivity.

---

## 5. Unused npm Dependencies

### `style-loader` - `admin/package.json:34`
- **What:** Webpack loader that injects CSS into the DOM via `<style>` tags
- **Why dead:** Never used. The webpack config uses `MiniCssExtractPlugin.loader` instead (which extracts CSS to separate files). `style-loader` is installed but not referenced in `webpack.config.js`.

---

## 6. Unused REST API Endpoints (registered but never called from frontend)

### `GET /analytics/volume` - `includes/class-tpz-rest-api.php:247`
- **What:** Analytics volume data endpoint
- **Why dead:** Never called from any JS file. The `analytics-dashboard.js` uses hardcoded demo data for the volume chart instead of calling this endpoint.

### `GET /analytics/costs` - `includes/class-tpz-rest-api.php:253`
- **What:** Analytics cost data endpoint
- **Why dead:** Never called from any JS file. The `analytics-dashboard.js` uses hardcoded demo data for the cost chart.

### `GET /analytics/predictions` - `includes/class-tpz-rest-api.php:265`
- **What:** Analytics predictions endpoint
- **Why dead:** Never called from any JS file.

---

## 7. Zombie Code (deprecated/commented-out blocks)

### `admin/src/styles/_modals.scss:658-end`
- **What:** Legacy permission table styles marked `// DEPRECATED`
- **Why dead:** CSS classes `.presszone-multilingual-perm-cell` and variants are defined here but never referenced in any JS or PHP file. The comment says to use `.presszone-multilingual-perm-grid` instead, but that class is also never referenced in JS/PHP.

---

## 8. Legacy Duplication (functional overlap)

### `admin/class-tpz-dashboard.php` (entire Dashboard class)
- **What:** Legacy dashboard controller that registers under Tools > translate.press.zone. Includes its own AJAX handlers, page rendering, asset enqueuing, and menu registration.
- **Status:** Technically alive (instantiated by Admin class, registers hooks), but duplicates functionality now handled by the SPA + REST API. It registers a separate menu entry under `Tools`, loads `admin/js/dashboard.js` and `admin/views/dashboard-page.php`. The main admin experience is the SPA at `admin.php?page=translate-press-zone`. This entire class and its associated files (`admin/js/dashboard.js`, `admin/views/dashboard-page.php`, `admin/views/jobs-tab.php`) represent a parallel legacy interface.

### `admin/views/dashboard-page.php` + `admin/views/jobs-tab.php`
- **What:** Server-rendered views for the legacy dashboard
- **Status:** Only loaded via the legacy Dashboard class (Tools > translate.press.zone). Not used by the SPA.

### `admin/js/dashboard.js`
- **What:** Legacy dashboard JavaScript
- **Status:** Only enqueued by the legacy Dashboard class. Not part of the webpack build or SPA.

### `admin/src/styles/pages/_dashboard-legacy.scss`
- **What:** CSS for the legacy dashboard (`.presszone-translate-dashboard` classes)
- **Status:** Compiled into main.css, used by the legacy dashboard views. Dead relative to the SPA.

### `admin/src/styles/pages/_migration-legacy.scss`
- **What:** CSS for the legacy migration wizard (`.presszone-migration-` classes)
- **Status:** Compiled into main.css, used by `admin/views/migration-wizard.php`. Functional but legacy.

---

## 9. Summary Statistics

| Category | Count |
|----------|-------|
| Dead PHP classes (entire files) | 3 |
| Dead PHP methods | 11 |
| Orphaned files | 13+ |
| Unused JS components | 15 |
| Unused npm dependencies | 1 |
| Unused REST endpoints | 3 |
| Deprecated CSS blocks | 1 |
| Legacy duplication (functional) | ~6 files |

---

## 10. Notes

- The **AnomalyDetector** class IS used -- instantiated in JobReceiver (class-tpz-jobreceiver.php:147). Not dead.
- The **ServiceRegistrar** class IS used -- instantiated in both Plugin and JobSender. Not dead.
- The **MetaBox** class, **BulkActions** class, **JobSender**, **JobReceiver**, **EstimateManager**, **CharacterEstimator**, **TranslationService**, **TranslationResult**, **SiteRegistrar**, **Logger**, **Database**, **Settings**, and all Bridge adapters (MPZ, WPML, Polylang, Null) are actively used. Not dead.
- The **Migration/Admin**, **Migration/MigrationManager**, **Migration/DataMapper** classes form a chain (Admin -> MigrationManager -> DataMapper) and are actively loaded.
- The `admin/src/sections/analytics-dashboard.js` IS used (imported by `dashboard.js`), but its volume/cost charts use hardcoded data rather than calling the registered REST endpoints.
- Component files like `Tooltip.js`, `Textarea.js`, `SortableList.js`, `Checkbox.js`, `Skeleton.js`, `Notice.js`, `Input.js`, `Select.js`, `Toggle.js`, `Spinner.js`, `Button.js`, `Card.js`, `EmptyState.js`, `PageHeader.js`, `Badge.js`, `Modal.js`, `Table.js`, `Tabs.js`, `ProgressBar.js`, `StatCard.js`, `Toast.js` are all actively imported by page modules. Not dead.
