PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / 2.3.1
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF v2.3.1
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 / api / tools.md

tools.md in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF 2.3.1, at docs/api/tools.md

76 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 # Tools Module — Internal State Reset
2
3 ## Overview
4
5 The `Imagify\Tools` module provides a one-click tool to reset Imagify's internal optimization state. This is the programmatic equivalent of deactivating and reactivating the plugin — it clears stale transients, process locks, and ActionScheduler jobs that can cause the bulk optimizer to appear stuck.
6
7 Settings, the API key, and user-data caches are intentionally left untouched.
8
9 ## Classes
10
11 | Class | Responsibility |
12 |-------|----------------|
13 | `Imagify\Tools\InternalStateList` | Single source of truth for the three canonical arrays (bulk transients, lock patterns, scheduler hooks). No dependencies, no constructor — safe to `require_once` from `uninstall.php`. |
14 | `Imagify\Tools\ResetInternalState` | Service that performs the actual cleanup. Iterates `InternalStateList` and issues the necessary `delete_transient()` calls, raw SQL DELETEs (via `$wpdb->prepare`), and `as_unschedule_all_actions()` calls. |
15 | `Imagify\Tools\Subscriber` | `SubscriberInterface` implementation that wires the AJAX action. |
16 | `Imagify\Tools\ServiceProvider` | DI wiring — registered in `config/providers.php`. |
17
18 ## AJAX Action
19
20 | Key | Value |
21 |-----|-------|
22 | Action name | `imagify_reset_internal_state` |
23 | Hook | `wp_ajax_imagify_reset_internal_state` |
24 | Method | POST |
25 | Nonce key | `_wpnonce` |
26 | Nonce action | `imagify_reset_internal_state` |
27 | Capability | `imagify_get_context('wp')->current_user_can('manage')` |
28
29 On success the endpoint returns:
30
31 ```json
32 { "success": true, "data": { "message": "Imagify internal state has been reset successfully." } }
33 ```
34
35 On capability failure `imagify_die()` is called (403). On nonce failure `imagify_check_nonce()` dies with the standard WordPress error.
36
37 **Nonce delivery:** The nonce must be sent as `_wpnonce` in the POST body. Sending it as `nonce` causes a silent 403 because `imagify_check_nonce()` delegates to `check_ajax_referer($action, false)`, which checks only `_ajax_nonce` and `_wpnonce`.
38
39 ## What Gets Cleared
40
41 ### Bulk running-state transients (`InternalStateList::get_bulk_transients()`)
42
43 - `imagify_custom-folders_optimize_running`
44 - `imagify_wp_optimize_running`
45 - `imagify_bulk_optimization_complete`
46 - `imagify_missing_next_gen_total`
47 - `imagify_bulk_optimization_result`
48 - `imagify_bulk_optimization_infos`
49 - `imagify_bulk_optimization_level` (legacy artifact, cleared for hygiene)
50
51 Note: this is a superset of `Bulk::delete_transients_data()`. The last two entries are not cleared by the Bulk deactivation hook.
52
53 ### Process-lock LIKE patterns (`InternalStateList::get_locked_transient_patterns()`)
54
55 SQL `DELETE … WHERE option_name LIKE` patterns run against `$wpdb->options`. On multisite a second query runs against `$wpdb->sitemeta`.
56
57 - `\_transient\_%imagify-auto-optimize-%` (legacy)
58 - `\_transient\_%imagify\_rpc\_%` (legacy)
59 - `\_transient\_imagify\_%\_process\_locked`
60 - `\_site\_transient\_imagify\_%\_process\_lock%`
61
62 ### ActionScheduler hooks (`InternalStateList::get_scheduler_hooks()`)
63
64 Unscheduled via `as_unschedule_all_actions()` (guarded by `function_exists`):
65
66 - `imagify_optimize_media`
67 - `imagify_convert_next_gen`
68
69 ## Extending the Lists
70
71 Add new items to `InternalStateList` — the single source of truth consulted by both `ResetInternalState` (live reset) and `uninstall.php` (plugin removal).
72
73 ## Multisite Notes
74
75 The `$wpdb->options` DELETE runs on every call. The `$wpdb->sitemeta` DELETE is guarded by `is_multisite()`. The reset is scoped to the current site — it does not iterate all network sites.
76