PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / docs / imagify-summary.md

imagify-summary.md in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at docs/imagify-summary.md

514 lines 18.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 # Imagify — Complete Technical Summary
2
3 > Version 2.2.8 · PHP 7.3+ · WordPress 5.3+
4 >
5 > WordPress image optimisation plugin — compression, next-gen formats (WebP / AVIF), and multi-context management.
6
7 ---
8
9 ## Table of Contents
10
11 1. [](#1-architecture--bootstrappingArchitecture & Bootstrapping](#1-architecture--bootstrapping](#1-architecture--bootstrapping)
12 2. [](#2-image-optimisationImage Optimisation](#2-image-optimisation](#2-image-optimisation)
13 3. [](#3-next-gen-formats-webp--avifNext-gen Formats (WebP / AVIF)](#3-next-gen-formats-webp--avif](#3-next-gen-formats-webp--avif)
14 4. [](#4-settings--configurationSettings & Configuration](#4-settings--configuration](#4-settings--configuration)
15 5. [](#5-bulk-optimisationBulk Optimisation](#5-bulk-optimisation](#5-bulk-optimisation)
16 6. [](#6-wordpress-media-library-integrationWordPress Media Library Integration](#6-wordpress-media-library-integration](#6-wordpress-media-library-integration)
17 7. [](#7-custom-foldersCustom Folders](#7-custom-folders](#7-custom-folders)
18 8. [](#8-ajax--admin-post-actionsAJAX & Admin-Post Actions](#8-ajax--admin-post-actions](#8-ajax--admin-post-actions)
19 9. [](#9-wp-cli-commandsWP-CLI Commands](#9-wp-cli-commands](#9-wp-cli-commands)
20 10. [](#10-nextgen-gallery-integrationNextGEN Gallery Integration](#10-nextgen-gallery-integration](#10-nextgen-gallery-integration)
21 11. [](#11-third-party-integrationsThird-Party Integrations](#11-third-party-integrations](#11-third-party-integrations)
22 12. [](#12-scheduled-tasks-cronScheduled Tasks (Cron)](#12-scheduled-tasks-cron](#12-scheduled-tasks-cron)
23 13. [](#13-developer-hooks--filtersDeveloper Hooks & Filters](#13-developer-hooks--filters](#13-developer-hooks--filters)
24 14. [](#14-quota--account-managementQuota & Account Management](#14-quota--account-management](#14-quota--account-management)
25 15. [](#15-roles--access-controlRoles & Access Control](#15-roles--access-control](#15-roles--access-control)
26 16. [](#16-troubleshooting-toolsTroubleshooting Tools](#16-troubleshooting-tools](#16-troubleshooting-tools)
27
28 ---
29
30 ## 1. Architecture & Bootstrapping
31
32 *Source code organisation, service loading, and plugin lifecycle.*
33
34 ### Entry Point
35
36 The plugin starts from `imagify.php`. It defines global constants, includes the Composer autoloader, then hooks the `imagify_init()` function on `plugins_loaded`.
37
38 **Key constants**
39 - `IMAGIFY_VERSION` — plugin version
40 - `IMAGIFY_PATH` / `IMAGIFY_URL`
41 - `IMAGIFY_MAX_BYTES` — 5 MB limit per image
42 - `IMAGIFY_APP_API_URL` — remote API URL
43 - `IMAGIFY_API_KEY` — override via PHP constant
44
45 **Autoloading & DI**
46 - PSR-4 via Composer (`vendor/autoload.php`)
47 - Dependency injection: **League Container**
48 - Providers declared in `config/providers.php`
49 - Main class: `Imagify\Plugin`
50 - Final hook: `do_action('imagify_loaded')`
51
52 ### Registered Service Providers
53
54 `User` · `Admin` · `Avif` · `CDN` · `Picture` · `Stats` · `Webp` · `ThirdParty` · `Media` · `Tools`
55
56 ### Initialisation Sequence
57
58 ```
59 // 1. plugins_loaded
60 imagify_init()
61 └── include vendor/autoload.php
62 └── new Imagify\Plugin()
63 └── load config/providers.php // register services
64 └── boot Options, Data, Auth
65 └── boot Auto-Optimization
66 └── (admin only) boot Settings, Views, Imagifybeat
67 └── do_action('imagify_loaded')
68 ```
69
70 ---
71
72 ## 2. Image Optimisation
73
74 *On-the-fly or bulk compression, quality levels, backup management, and resizing.*
75
76 ### Compression Levels
77
78 | Level | Name | Description |
79 |-------|------|-------------|
80 | `0` | Normal | Light compression, maximum quality preserved. |
81 | `1` | Aggressive | Stronger compression, good quality/size trade-off. |
82 | `2` | Ultra (default) | Maximum compression — recommended for most use cases. |
83
84 > All optimisation operations go through the `Imagify\Optimization\File` class, which communicates with the remote Imagify API.
85
86 ### Automatic Optimisation on Upload
87
88 When the `auto_optimize` option is enabled, the `Imagify_Auto_Optimization` class hooks into `wp_generate_attachment_metadata`. Each uploaded image is optimised immediately, along with all its thumbnails.
89
90 ### Backup System
91
92 - Enabled via the `backup` option.
93 - The original file is copied before any compression.
94 - Backup directory is filterable via `imagify_backup_directory`.
95 - Restoring puts the original back in place and removes optimisation metadata.
96
97 ### Large Image Resizing
98
99 - Option `resize_larger`: when enabled, images exceeding `resize_larger_w` pixels wide are resized.
100 - Default value: **2560 px** (aligned with the WP filter `big_image_size_threshold`).
101
102 ### Thumbnail Management
103
104 All sizes registered in WordPress are optimised. Sizes can be excluded via the `disallowed-sizes` blacklist in the settings.
105
106 ### Optimisation Statuses
107
108 `success` · `already_optimized` · `error` · `pending`
109
110 ### Metadata Stored Per Attachment
111
112 ```
113 // Attachment post meta
114 _imagify_status // 'success' | 'already_optimized' | 'error' | 'pending'
115 _imagify_data // JSON — full optimisation results
116 _imagify_level // Level used (0, 1, 2)
117 _imagify_next_gen_done // Boolean — next-gen versions generated
118 ```
119
120 ---
121
122 ## 3. Next-gen Formats (WebP / AVIF)
123
124 *Generation and delivery of modern formats to reduce image weight on the browser side.*
125
126 ### File Generation
127
128 After optimisation, Imagify can generate **WebP** and/or **AVIF** versions of each image. The `optimization_format` option controls this behaviour:
129
130 | Value | Behaviour |
131 |-------|-----------|
132 | `'off'` | No next-gen format. |
133 | `'webp'` | Generates WebP only. |
134 | `'avif'` | Generates WebP + AVIF (AVIF takes priority if supported). |
135
136 ### Display Method: `<picture>`
137
138 Class: `Imagify\Picture\Display`. The plugin starts an output buffer on `template_redirect`, scans the generated HTML, and replaces each `<img>` with a `<picture>` block containing `<source>` elements pointing to the WebP/AVIF files.
139
140 ```html
141 <!-- Before -->
142 <img src="photo.jpg" alt="...">
143
144 <!-- After transformation -->
145 <picture>
146 <source srcset="photo.avif" type="image/avif">
147 <source srcset="photo.webp" type="image/webp">
148 <img src="photo.jpg" alt="...">
149 </picture>
150 ```
151
152 ### Display Method: Server Rewrite
153
154 Class: `Imagify\Webp\Display`. Rather than altering the HTML, rules are written directly into `.htaccess` (Apache) or `web.config` (IIS). The server automatically serves WebP if the browser accepts it (`Accept: image/webp`).
155
156 **Lazy Load compatibility:** The `data-lazy-src`, `data-src`, `data-srcset`, `data-lazy-srcset` attributes are detected and propagated into the generated `<source>` and `<img>` tags.
157
158 **Image exclusion:** An image with the CSS class `imagify-no-webp` is ignored by the `<picture>` transformation.
159
160 > **Warning:** the server rewrite method requires the web server to be Apache or IIS and that the configuration files (.htaccess) be writable.
161
162 ---
163
164 ## 4. Settings & Configuration
165
166 *All options stored in `imagify_settings` (wp_options / wp_sitemeta on multisite).*
167
168 | Key | Type | Default | Description |
169 |-----|------|---------|-------------|
170 | `api_key` | string | `''` | Imagify API key (or the `IMAGIFY_API_KEY` constant). |
171 | `optimization_level` | int | `2` | Compression level (0, 1, 2). |
172 | `lossless` | bool | `0` | Lossless compression. |
173 | `auto_optimize` | bool | `1` | Automatic optimisation on upload. |
174 | `backup` | bool | `1` | Back up the original before compression. |
175 | `resize_larger` | bool | `0` | Resize images that are too large. |
176 | `resize_larger_w` | int | `0` | Maximum width in pixels. |
177 | `optimization_format` | string | `'webp'` | `'off'`, `'webp'`, or `'avif'`. |
178 | `display_nextgen_method` | string | `'picture'` | `'picture'` or `'rewrite'`. |
179 | `cdn_url` | string | `''` | CDN URL for serving media. |
180 | `disallowed-sizes` | array | `[]` | Thumbnail sizes excluded from optimisation. |
181 | `admin_bar_menu` | bool | `1` | Show Imagify in the admin bar. |
182
183 > The `Imagify_Settings` class handles option registration (`register_setting()`) and validation. It is network-aware: on multisite, network options are stored in `wp_sitemeta`.
184
185 ---
186
187 ## 5. Bulk Optimisation
188
189 *Batch processing of all existing images, with an asynchronous queue.*
190
191 ### Bulk Architecture
192
193 The `Imagify\Bulk\Bulk` class orchestrates bulk optimisation. It relies on **ActionScheduler** (bundled library) to create asynchronous jobs processed in the background.
194
195 | Context | Class | Description |
196 |---------|-------|-------------|
197 | WP Media | `Imagify\Bulk\WP` | Optimises all attachments in the WordPress media library that have not yet been optimised. |
198 | Custom Folders | `Imagify\Bulk\CustomFolders` | Optimises files indexed in the custom folders. |
199 | NGG | `Imagify\Bulk\NGG` | Optimises images from NextGEN Gallery galleries. |
200
201 ### Execution Flow
202
203 ```
204 // Trigger (UI or CLI)
205 imagify_bulk_optimize (AJAX) // or wp imagify bulk-optimize
206 └── Imagify\Bulk\Bulk::run()
207 └── ActionScheduler::enqueue(imagify_optimize_media)
208 └── Imagify\Job\MediaOptimization::execute()
209 └── Imagify\Optimization\File::optimize()
210 └── Remote Imagify API
211 ```
212
213 ### Bulk Next-gen Version Generation
214
215 The AJAX action `imagify_missing_nextgen_generation` and the ActionScheduler hook `imagify_convert_next_gen` allow generating WebP/AVIF versions for all already-optimised images whose next-gen files are missing.
216
217 ---
218
219 ## 6. WordPress Media Library Integration
220
221 *Columns, actions, and buttons directly within the WordPress media interface.*
222
223 **List view (Media Library)**
224 - "Imagify" column with status and weight savings.
225 - Inline action buttons: Optimize, Re-optimize, Restore, Generate next-gen, Delete next-gen.
226 - "Bulk Optimization" group action.
227 - Filter by status: `?imagify-status=...` (`optimized`, `unoptimized`, `errors`, `missing-nextgen`).
228 `missing-nextgen` (list mode only) is applied via `Imagify\Media\Subscriber::filter_missing_nextgen_query()`
229 on `pre_get_posts`, and shows optimized WP media with no successful next-gen size recorded (mirroring
230 the predicate used for the "missing next-gen" count).
231
232 **Attachment edit page**
233 - Dedicated metabox with detailed status.
234 - Individual optimisation buttons.
235 - Display of savings achieved (KB and %).
236 - Restore link to the original.
237
238 > The WordPress admin bar can also display a shortcut to the Bulk Optimization page, controlled by the `admin_bar_menu` option.
239
240 ---
241
242 ## 7. Custom Folders
243
244 *Optimisation of image files located outside the WordPress media library.*
245
246 Custom folders allow optimising images located anywhere on the server (themes, plugins, custom directories). They are indexed in two dedicated MySQL tables.
247
248 | Table | Contents |
249 |-------|----------|
250 | `imagify_folders` | Monitored directories, absolute path on the server, scan status |
251 | `imagify_files` | Individually indexed files, original/optimised size, status, level, generated formats, hash to detect modifications |
252
253 ### Available Features
254 - **Scan**: automatic detection of new images in configured folders.
255 - **Individual or bulk optimisation** via the same ActionScheduler system.
256 - **Re-optimisation**: if the source file has been modified (detected by hash).
257 - **Restore** from backup.
258 - **Cron synchronisation** to detect modified/deleted files.
259
260 ### Main Classes
261
262 ```php
263 // Database access
264 Imagify_Files_DB // CRUD on wp_imagify_files
265 Imagify_Folders_DB // CRUD on wp_imagify_folders
266 Imagify_Files_Scan // Filesystem scan
267
268 // Context
269 Imagify\Context\CustomFolders
270 ```
271
272 ---
273
274 ## 8. AJAX & Admin-Post Actions
275
276 *All server entry points used by the administration interface.*
277
278 > The plugin does not expose a standard WordPress REST API. All actions go through `wp_ajax_*` (authenticated) or `admin_post_*`. A custom "Imagifybeat" system handles real-time updates.
279
280 ### AJAX Actions (`wp_ajax_*`)
281
282 **Account & API**
283 - `imagify_signup`
284 - `imagify_check_api_key_validity`
285 - `imagify_get_user_data`
286 - `imagify_delete_user_data_cache`
287 - `imagify_get_prices`
288 - `imagify_check_coupon`
289
290 **Bulk & stats**
291 - `imagify_bulk_optimize`
292 - `imagify_missing_nextgen_generation`
293 - `imagify_bulk_get_stats`
294 - `imagify_get_folder_type_data`
295 - `imagify_bulk_info_seen`
296 - `imagify_get_images_counts`
297
298 **UI & settings**
299 - `imagify_check_backup_dir_is_writable`
300 - `imagify_get_files_tree`
301 - `imagify_update_estimate_sizes`
302
303 **Tools**
304 - `imagify_reset_internal_state`
305 - `imagify_rpc` (Imagifybeat)
306
307 ### Admin-Post Actions (`admin_post_*`)
308
309 **WP Media Library**
310 - `imagify_manual_optimize`
311 - `imagify_manual_reoptimize`
312 - `imagify_optimize_missing_sizes`
313 - `imagify_generate_nextgen_versions`
314 - `imagify_delete_nextgen_versions`
315 - `imagify_restore`
316
317 **Custom Folders**
318 - `imagify_optimize_file`
319 - `imagify_reoptimize_file`
320 - `imagify_restore_file`
321 - `imagify_refresh_file_modified`
322 - `imagify_scan_custom_folders`
323
324 ### Imagifybeat
325
326 Real-time update system (analogous to WordPress Heartbeat). Hook: `wp_ajax_imagifybeat`. Interface data (nonces, statuses) is refreshed periodically via AJAX polling, configurable by filter.
327
328 ---
329
330 ## 9. WP-CLI Commands
331
332 *Command-line interface for automating optimisation operations.*
333
334 ### `wp imagify bulk-optimize`
335 Launches bulk optimisation for one or more contexts (`wp`, `custom-folders`).
336 - Option: `--optimization-level`
337 - Asynchronous execution via ActionScheduler
338
339 ### `wp imagify restore`
340 Restores original images for the specified contexts (`library`, `custom-folders`).
341 - Synchronous (blocking) execution
342 - Returns: success, errors, total
343
344 ### `wp imagify generate-missing-nextgen`
345 Generates missing WebP/AVIF versions for all already-optimised images.
346 - Useful after enabling a next-gen format
347
348 ---
349
350 ## 10. NextGEN Gallery Integration
351
352 *Full support for the NextGEN Gallery (NGG) plugin.*
353
354 The plugin automatically detects NextGEN Gallery and activates a dedicated context (`Imagify\Context\NGG`).
355
356 **Features**
357 - Optimisation of NGG images (levels 0/1/2)
358 - WebP / AVIF generation for NGG images
359 - Restore NGG originals
360 - Backup before compression
361
362 **Interface**
363 - "Bulk Optimization" page in the NGG menu
364 - "Imagify" column in "Manage Images"
365 - Verified compatibility: NGG v4.x (`imagify_ngg_has_pope_storage()`)
366
367 ---
368
369 ## 11. Third-Party Integrations
370
371 ### Plugins
372
373 WooCommerce · WP Rocket · Gravity Forms · Formidable Pro · Yoast SEO · AMP · Enable Media Replace · Regenerate Thumbnails · Amazon S3 & CloudFront · Real Media Library · Extendify · Cloudflare Super Page Cache
374
375 **WooCommerce detail:** On variable product pages, WooCommerce dynamically replaces the main image. Imagify fixes the `wp-post-image` class on generated `<picture>` tags to maintain compatibility with WooCommerce's image-switching mechanism.
376
377 ### Hosting Providers
378
379 WordPress.com · WP Engine · Flywheel · SiteGround · Pressable
380
381 ---
382
383 ## 12. Scheduled Tasks (Cron)
384
385 *Recurring jobs for maintenance and statistics.*
386
387 | Task | WP Cron Hook | Frequency | Role |
388 |------|-------------|-----------|------|
389 | `Imagify_Cron_Rating` | `imagify_rating_event` | Daily (3:00 PM) | Triggers the plugin rating request. |
390 | `Imagify_Cron_Library_Size` | — | Periodic | Recalculates media library statistics. |
391 | `Imagify_Cron_Sync_Files` | — | Periodic | Synchronises files in custom folders. |
392
393 ### ActionScheduler
394
395 The ActionScheduler library is bundled in `/inc/Dependencies/ActionScheduler/`. It manages asynchronous optimisation jobs:
396
397 - `imagify_optimize_media` — Processes a single optimisation job.
398 - `imagify_convert_next_gen` — Generates next-gen versions.
399
400 All jobs are cleaned up when the plugin is deactivated.
401
402 ---
403
404 ## 13. Developer Hooks & Filters
405
406 *Extension points for customising the plugin's behaviour.*
407
408 ### Main Actions
409
410 | Hook | When |
411 |------|------|
412 | `imagify_loaded` | Plugin fully loaded and ready. |
413 | `imagify_activation` | On plugin activation. |
414 | `imagify_deactivation` | On plugin deactivation. |
415 | `imagify_optimize_media` | ActionScheduler optimisation job. |
416 | `imagify_convert_next_gen` | Next-gen generation job. |
417 | `imagify_delete_media` | Deletion of a media item. |
418 | `imagify_settings_on_save` | After settings are saved. |
419 | `imagify_not_over_quota_anymore` | Quota dropped back below 100%. |
420
421 ### Main Filters
422
423 | Filter | Usage |
424 |--------|-------|
425 | `imagify_backup_directory` | Change the backup folder. |
426 | `imagify_register_context` | Register a custom optimisation context. |
427 | `imagify_picture_attributes` | Modify attributes of the `<picture>` tag. |
428 | `imagify_picture_source_attributes` | Modify attributes of `<source>` tags. |
429 | `imagify_picture_img_attributes` | Modify attributes of the inner `<img>`. |
430 | `imagify_allow_picture_tags_for_nextgen` | Disable the `<picture>` transformation. |
431 | `imagify_buffer` | Filter the final HTML page buffer. |
432 | `imagify_cdn_source_url` | Override the CDN URL. |
433 | `imagify_event_recurrence` | Change the frequency of Imagify cron jobs. |
434 | `imagify_site_root_url` | Override the site root URL used for internal-URL matching (e.g. multisites with domain mapping). |
435 | `imagify_event_time` | Change the trigger time for cron jobs. |
436 | `imagify_bulk_stats` | Modify bulk statistics data. |
437 | `imagify_unoptimized_attachment_limit` | Limit query results. |
438
439 ---
440
441 ## 14. Quota & Account Management
442
443 *Subscription plans, quota consumption, and user data cache.*
444
445 ### Available Plans
446
447 | Plan | `plan_id` | Description |
448 |------|----------|-------------|
449 | **Free** | `1` | Limited monthly quota. Blocked at 100% consumption (`is_over_quota()`). |
450 | **Growth** | `16` / `18` | Larger monthly quota, additional byte packs available. |
451 | **Infinite** | `15` / `17` | Unlimited quota — no quota blocking. |
452
453 ### Data Exposed by `Imagify\User\User`
454
455 ```
456 quota // Total monthly quota (MB)
457 consumed_current_month_quota // Quota consumed this month (MB)
458 extra_quota // Imagify byte pack (MB)
459 extra_quota_consumed // Pack consumed (MB)
460 next_date_update // Quota reset date
461 is_active // Account active
462 ```
463
464 ### Cache
465
466 User data is cached in a WordPress transient (`imagify_user_cache`) for **5 minutes**. The cache can be manually cleared via the AJAX action `imagify_delete_user_data_cache`.
467
468 ---
469
470 ## 15. Roles & Access Control
471
472 *WordPress capabilities required for each Imagify action.*
473
474 | Action | Required WP Capability | Context |
475 |--------|----------------------|---------|
476 | `manage` — Access settings | `manage_options` | All |
477 | `optimize` — Optimize a media item | `upload_files` | All |
478 | `bulk-optimize` — Launch a bulk run | `manage_options` | All |
479
480 > Capabilities are defined in `Imagify\Context\AbstractContext::get_capacity()` and can be overridden via the standard WordPress filter `option_page_capability_imagify`.
481
482 ---
483
484 ## 16. Troubleshooting Tools
485
486 *Built-in tools to resolve common issues without technical intervention.*
487
488 ### Internal State Reset
489
490 AJAX action: `imagify_reset_internal_state` (requires the `manage` capability). This one-click tool unblocks the bulk optimiser when it gets stuck in an inconsistent state.
491
492 ### What Gets Cleaned Up
493
494 **Deleted transients**
495 - `imagify_custom-folders_optimize_running`
496 - `imagify_wp_optimize_running`
497 - `imagify_bulk_optimization_complete`
498 - `imagify_bulk_optimization_result`
499 - `imagify_missing_next_gen_total`
500 - `imagify_bulk_optimization_infos`
501
502 **Deleted locks & jobs**
503 - Auto-optimize locks (`_transient_%imagify-auto-optimize-%`)
504 - RPC locks (`_transient_%imagify_rpc_%`)
505 - Process locks (`_transient_imagify_%_process_locked`)
506 - ActionScheduler jobs: `imagify_optimize_media`
507 - ActionScheduler jobs: `imagify_convert_next_gen`
508
509 > The `Imagify\Tools\InternalStateList` class is the single source of truth for all these items — it is also used by `uninstall.php` for a full cleanup on uninstallation.
510
511 ---
512
513 *Imagify v2.2.8 · wp-media/imagify-plugin*
514