Skip to content

Feature/ajax Save Ux#26

Merged
jasperf merged 10 commits into
mainfrom
feature/ajax-save-ux
May 28, 2026
Merged

Feature/ajax Save Ux#26
jasperf merged 10 commits into
mainfrom
feature/ajax-save-ux

Conversation

@jasperf

@jasperf jasperf commented May 28, 2026

Copy link
Copy Markdown
Contributor

This release (1.5.2) introduces an AJAX-driven settings save experience for the Cookie Consent admin page, eliminating full-page reloads when administrators update plugin configuration. The bulk of the change extracts inline admin JavaScript into a dedicated assets/js/admin.js module that intercepts the settings form submission, posts to admin-ajax.php, and renders an in-page notice scrolled into view on completion. Add-cookie subforms are now rendered outside the main settings form to prevent nested-form HTML invalidity, with an explicit redirect-after-POST notice surfaced when a cookie row is added. The setup nag notice now self-suppresses once the plugin has been configured, and supporting documentation (docs/admin-ajax-comparison.md, docs/architecture-plan.md) plus a .vibe workflow config have been added to capture the architectural rationale.

Admin UX and AJAX Save Flow:

  • Added assets/js/admin.js implementing AJAX submission of the settings form with an inline success/error notice that is scrolled into the viewport after save (a7e18db, 34452c4).
  • Moved add-cookie forms outside the main settings <form> to avoid invalid nested-form markup, and added a redirect-after-POST notice so administrators see confirmation when a new cookie row is created (fb09e7c).
  • Added a guard that skips the AJAX intercept when the submitted form is an add-cookie form, ensuring those continue to use the standard POST/redirect cycle (0a8f1f7).
  • Removed obsolete form-nesting workarounds from admin.js after the structural fix made them unnecessary (0f8d9cd).

Plugin Behavior and PHP Changes:

  • The setup notice now self-suppresses once warder_options reflects a configured state, preventing the "please configure" prompt from persisting after first save (5299221).
  • Updated warder-cookie-consent.php to register the new admin script, expose the AJAX endpoint and nonce, and handle the AJAX save callback alongside the existing settings save path.
  • Version bumped to 1.5.2 across warder-cookie-consent.php, readme.txt, CHANGELOG.md, and package.json per the project's versioning policy (924ec17).

Documentation and Tooling:

  • Added docs/admin-ajax-comparison.md and docs/architecture-plan.md to document the AJAX save design and align the broader architectural plan with the current warder_ codebase conventions (cc9bb26).
  • Introduced .vibe/config.toml and .vibe/prompts/vibe.md for project workflow tooling, with .distignore and .gitattributes updated to exclude these from distribution builds and Composer/WordPress.org exports (96488f3, ee7b31d).
  • Refreshed CLAUDE.md to reflect the warder_ function-prefix conventions and the new admin asset layout.

Files Changed:

jasperf added 10 commits May 28, 2026 10:50
Replace outdated scc_ prefix references with warder_ throughout CLAUDE.md,
update the PHP layer section to reflect the actual file and function names,
expand the settings structure, and correct the Composer package name.

Rewrite docs/architecture-plan.md to accurately describe current state,
adopt AJAX save as the single recommended approach for Phase 1, add a
Phase 2 for extracting inline admin JS to a file, and incorporate relevant
WordPress.org plugin guideline references (Guidelines 4, 7, 8, 11, 13).
Add warder_ajax_save_settings() AJAX handler that verifies the nonce
and capability, runs input through the existing warder_validate_options(),
and returns a JSON success/error response so the page never reloads on save.

Extract the inline $admin_js heredoc to assets/js/admin.js and enqueue it
as a proper script handle (warder-admin) with a jquery dependency. Add the
WARDER_VERSION constant and use wp_localize_script to pass the ajaxurl and
translated button-label strings (warderAdmin.save / warderAdmin.saving)
instead of hardcoding them. The no-JS fallback via options.php is preserved.
The welcome notice on other admin pages now checks for the presence of
warder_options_last_updated before rendering. This option is written on
every settings save, so the notice disappears automatically after the
first save and does not keep appearing site-wide (WP.org Guideline 11).
The main form's submit handler was firing for the add-cookie submit
button (which uses form= to target a separate form), preventing
is_regex and other add-cookie fields from reaching PHP.

Co-Authored-By: Jasper Frumau <jasper@imagewize.com>
Co-Authored-By: Jasper Frumau <jasper@imagewize.com>
Co-Authored-By: Jasper Frumau <jasper@imagewize.com>
…OST notice

The add-cookie container was nested inside #warder-main-settings-form,
requiring the HTML5 `form` attribute to associate inputs with a hidden
target form. Browsers handle `display:none` target forms inconsistently,
causing the checkbox state to be lost and the AJAX save handler to
intercept add-cookie submissions.

Moves each add-cookie container (now a full self-contained <form>) to
render after the main form in the DOM. Adds a redirect-after-POST in
warder_handle_admin_actions() so all cookie/category changes show a
success notice via ?warder_notice=saved.

Co-Authored-By: Jasper Frumau <jasper@imagewize.com>
… on open

- After AJAX save, animate scroll to the inserted notice so it is
  always visible regardless of current scroll position
- When opening an add-cookie form, move its container immediately after
  the main settings form and scroll to it, keeping it out of the main
  form's DOM subtree
- Scope the submit-button disable/enable to :not([form]) to avoid
  touching add-cookie submit buttons
- Exclude inputs with a `form` attribute from the unsaved-change
  highlight so the add-cookie checkbox no longer turns yellow

Co-Authored-By: Jasper Frumau <jasper@imagewize.com>
Add-cookie containers now render after the main form in PHP and no
inputs use the HTML5 form= attribute, so the JS workarounds added when
the forms were nested are no longer needed:

- Remove the .after() reposition of add-cookie containers
- Remove :not([form]) filters from the change-highlight selector
- Remove :not([form]) filter from the submit-button lookup
Bump Version/WARDER_VERSION in the main plugin file, Stable tag in
readme.txt, version in package.json, and add 1.5.2 entries to
CHANGELOG.md and readme.txt (== Changelog == and == Upgrade Notice ==).

Also tracks docs/admin-ajax-comparison.md, an analysis of the recent
form-nesting issues and modern-plugin AJAX patterns that informed the
admin.js cleanup in 0f8d9cd.
@jasperf
jasperf merged commit 17fa4e8 into main May 28, 2026
2 checks passed
@jasperf
jasperf deleted the feature/ajax-save-ux branch May 28, 2026 05:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant