feat(tools): add one-click Reset Internal State troubleshooting tool#1085
Conversation
Adds a 'Reset Internal State' button to the Imagify Settings page that clears stale optimization transients, process locks, and pending ActionScheduler jobs — replicating the deactivation cleanup without touching user settings or media optimization records. New module: classes/Tools/ (InternalStateList, ResetInternalState, Subscriber, ServiceProvider). InternalStateList is autoloader-free so uninstall.php can require_once it before the container is bootstrapped. Multisite: also clears sitemeta process locks via a separate DELETE. All DB queries use $wpdb->prepare + $wpdb->esc_like (no raw SQL). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…te tool Adds the settings page UI for the one-click internal state reset: views/part-settings-tools.php template with data-nonce button, JS click handler in options.js posting _wpnonce to the AJAX endpoint, i18n strings in the options localization, and a Playwright E2E spec. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 10 |
| Duplication | 0 |
🟢 Coverage 76.19% diff coverage
Metric Results Coverage variation Report missing for 35156381 Diff coverage ✅ 76.19% diff coverage (50.00%) Coverage variation details
Coverable lines Covered lines Coverage Common ancestor commit (3515638) Report Missing Report Missing Report Missing Head commit (da413e6) 18536 246 1.33% Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch:
<coverage of head commit> - <coverage of common ancestor commit>Diff coverage details
Coverable lines Covered lines Diff coverage Pull request (#1085) 63 48 76.19% Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified:
<covered lines added or modified>/<coverable lines added or modified> * 100%1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…I docs - Add capital-letter short descriptions to all test method doc comments - Add @inheritdoc short descriptions to setUp()/tearDown() doc comments - Add phpcs:ignore for intentional WordPress.WP.GlobalVariablesOverride in test setup - Add docs/api/tools.md documenting the AJAX action, what gets cleared, and multisite notes Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Note Generated by the AI delivery pipeline (lead-reviewer · claude-sonnet-4-6). Review: ❌ CHANGES REQUESTED Blockers:
Nice-to-haves:
|
Spec step 3 mandates the AJAX callback method name is `reset_internal_state`; `handle_reset` was used by mistake. Pure rename — no logic changes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…sses/ - InternalStateList::get_locked_transient_patterns() now returns plain (unescaped) strings; ResetInternalState::reset() assembles safe LIKE patterns via esc_like() on each segment, fixing the pre-escaped pattern issue raised in the lead-reviewer HIGH finding. - phpunit.xml.dist coverage include now covers classes/ alongside inc/, so Codacy diff coverage reports on new PSR-4 code. - Add Test_ResetInternalState test for Subscriber::reset_internal_state() covering the authorized and unauthorized AJAX handler paths. - Update existing reset.php tests to mock esc_like() on $wpdb. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
The text is very compact in the popup. It might be worth spacing it out a bit by adding something like: to the CSS. |


Note
🤖 This PR was generated by the AI delivery pipeline (orchestrator · Claude Sonnet 4.6). All code was reviewed by the lead-reviewer and QA agents before this PR was marked ready.
Description
Closes #1012
Adds a Troubleshooting section to the Imagify Settings page with a "Reset Internal State" button. Clicking the button POSTs to a new AJAX endpoint that clears stale optimization transients, process locks, and pending ActionScheduler jobs — the same cleanup that occurs on plugin deactivation, without touching user settings or media optimization records.
This resolves the most common "optimization stuck" support case with a single click, without requiring deactivate/reactivate.
Type of change
Detailed scenario
What was tested
Manual scenario 1 — Troubleshooting section visible with valid API key:
Manual scenario 2 — Section absent without API key:
is_api_key_valid()block).Manual scenario 3 — JS handler wires up correctly:
#imagify-reset-internal-statebutton has a non-emptydata-nonceattribute via browser DevTools.imagifyOptions.resetInternalStateis available in the page JS via browser console.Manual scenario 4 — Nonce key is
_wpnonce:_wpnoncekey present (not barenonce).Manual scenario 5 — Build passes:
npm run buildsucceeds with no errors.assets/js/options.min.jsrebuilt from source.Manual scenario 6 — PHPCS passes:
composer phpcs -- views/part-settings-tools.php inc/functions/i18n.php views/page-settings.phpreturns 0 errors.How to test
admin-ajax.phpwithaction=imagify_reset_internal_stateand_wpnonce=<token>.WP_DEBUGon, running a forced bulk optimization then resetting should unblock it.Affected Features & Quality Assurance Scope
imagify_reset_internal_stateendpoint (capability-checked, nonce-verified).InternalStateList; no frontend impact.Technical description
Documentation
The full technical documentation is in
docs/api/tools.md:imagify_reset_internal_statewith nonce actionimagify_reset_internal_state.data-nonceattribute on the button (same pattern asbackup-dir-is-writable)._wpnoncein the request body — required byimagify_check_nonce()/check_ajax_referer().imagifyOptions.resetInternalState(action, confirm text, success/error labels).New dependencies
None. No new PHP or JS dependencies. SweetAlert and jQuery already loaded with the
optionsscript handle.Risks
imagify_get_context('wp')->current_user_can('manage')). No unauthenticated access possible.is_multisite(); reset is scoped to current site only. Documented in PR anddocs/api/tools.md.Acceptance Criteria
manage_optionscapability can trigger the resetMandatory Checklist
Code validation
Code style
Unticked items justification
wp_send_json_success()on success andwp_send_json_error()on failure. User-facing feedback is in the JS layer (success/error strings inimagifyOptions.resetInternalState). No raw server-side log messages are exposed to end users; the feedback strings are translatable and human-readable.Additional Checks