Skip to content

Commit 3a90960

Browse files
dev: add AGENTS.md
1 parent 4a803da commit 3a90960

2 files changed

Lines changed: 114 additions & 0 deletions

File tree

.distignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,4 @@ test-results
4949
wp-scripts.config.js
5050
README.md
5151
CHANGELOG.md
52+
AGENTS.md

AGENTS.md

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Agent Workflow
2+
3+
## What This Is
4+
5+
Optimole WordPress plugin — cloud-based image optimization with CDN delivery, lazy loading, WebP/AVIF conversion, media offloading, and a Digital Asset Management (DAM) interface. Version 4.2.1, requires PHP 7.4+, WordPress 5.5+.
6+
7+
## Build & Dev Commands
8+
9+
```bash
10+
# Install dependencies
11+
npm install && composer install
12+
13+
# Build all assets (production)
14+
npm run build
15+
16+
# Development with HMR (all targets in parallel)
17+
npm run dev
18+
19+
# Build individual targets
20+
npm run build:dashboard # Admin settings UI
21+
npm run build:widget # Dashboard widget
22+
npm run build:media # Media library integration
23+
npm run build:optimizer # Frontend lazy loading script
24+
npm run build:video-player-editor
25+
npm run build:video-player-frontend
26+
```
27+
28+
## Testing
29+
30+
```bash
31+
# PHP unit tests (requires WP test suite)
32+
composer phpunit
33+
composer install-wp-tests # First-time setup
34+
35+
# Run a specific PHP test file
36+
phpunit tests/test-replacer.php
37+
38+
# Run a specific test method
39+
phpunit --filter="test_method_name"
40+
41+
# JavaScript tests
42+
npm test
43+
npm run test:watch
44+
npm run test:coverage
45+
46+
# E2E tests (Playwright, base URL: http://testing.optimole.com)
47+
npm run e2e:run
48+
npm run e2e:open # Interactive UI mode
49+
```
50+
51+
## Linting & Static Analysis
52+
53+
```bash
54+
# JavaScript
55+
npm run lint # ESLint
56+
npm run format # ESLint --fix
57+
58+
# PHP
59+
composer phpcs # PHP CodeSniffer (WordPress-Core standard)
60+
composer format # Auto-fix with phpcbf
61+
composer phpstan # PHPStan level 2
62+
```
63+
64+
## Architecture
65+
66+
### Two-era codebase: v1 (legacy) and v2 (modern)
67+
68+
**Legacy code (`inc/*.php`)** — Class prefix `Optml_*`, loaded by custom autoloader in `optimole-wp.php`. This is the bulk of the plugin.
69+
70+
**Modern code (`inc/v2/`)** — PSR-4 autoloaded under `OptimoleWP\` namespace via Composer. New features should go here.
71+
72+
### Plugin initialization flow
73+
74+
```
75+
optimole-wp.php → optml() → Optml_Main::instance() (singleton)
76+
├── Optml_Manager — Orchestrates replacers and loads compatibilities
77+
├── Optml_Admin — Admin dashboard UI, conflict detection
78+
├── Optml_Rest — REST API endpoints for the dashboard
79+
├── Optml_Media_Offload — Cloud offloading/restoration of media
80+
├── Optml_Dam — Digital Asset Management UI
81+
├── Optml_Video_Player — Video player blocks
82+
└── Optml_Cli — WP-CLI commands (when available)
83+
```
84+
85+
### Core subsystems
86+
87+
- **URL/Tag replacement** (`tag_replacer.php`, `url_replacer.php`, `app_replacer.php`) — Parses HTML output, rewrites image URLs to Optimole CDN URLs with optimization parameters.
88+
- **Lazy loading** (`lazyload_replacer.php`, `inc/v2/BgOptimizer/`) — Viewport-based and background-image lazy loading. Frontend JS in `assets/js/optimizer.js`.
89+
- **Media offloading** (`media_offload.php`) — Moves media to/from Optimole cloud storage, handles bulk operations.
90+
- **Settings** (`settings.php`) — Central settings schema and management, stores in `wp_options`.
91+
- **Compatibility layer** (`inc/compatibilities/`) — 49+ integrations for page builders (Elementor, Divi, Beaver Builder), caching plugins (WP Rocket, LiteSpeed), WooCommerce, etc. Each extends `Optml_compatibility`.
92+
93+
### Frontend assets (`assets/src/`)
94+
95+
React-based, built with `@wordpress/scripts`:
96+
- `dashboard/` — Main admin settings page (React + @wordpress/components)
97+
- `widget/` — Admin dashboard widget
98+
- `media/` — Media library DAM integration
99+
- `video-player/` — Editor and frontend video player blocks
100+
101+
Built output goes to `assets/build/`. The `assets/js/optimizer.js` is the frontend lazy-loading script.
102+
103+
## Code Standards
104+
105+
- **PHP**: WordPress-Core via PHPCS. Text domain: `optimole-wp`.
106+
- **JS**: WordPress ESLint config. Tabs, single quotes, semicolons.
107+
- **v2 PHP code** requires PHPStan-compatible PHPDoc annotations, full namespace paths, type hints, and constants for magic values (e.g., `Profile::DEVICE_TYPE_MOBILE` not `1`).
108+
- Error handling: return `WP_Error` for WordPress-compatible errors, `false` for simple failures.
109+
- Debug logging: `do_action( 'optml_log', $message )` when `OPTML_DEBUG` is true.
110+
111+
## Key Constants
112+
113+
Defined in `optimole-wp.php`: `OPTML_URL`, `OPTML_PATH`, `OPTML_VERSION`, `OPTML_NAMESPACE` (`'optml'`), `OPTML_BASEFILE`, `OPTML_DEBUG`, `OPTML_DEBUG_MEDIA`.

0 commit comments

Comments
 (0)