Skip to content

[CONS-505] fix(admin): unnest Sync Roles form so Users settings save - #26

Merged
bordoni merged 2 commits into
mainfrom
fix/users-settings-nested-form-save
Jun 9, 2026
Merged

bordoni merged 2 commits into
mainfrom
fix/users-settings-nested-form-save

Conversation

@skyshab

@skyshab skyshab commented Jun 9, 2026 •

Copy link
Copy Markdown
Collaborator

Linear: CONS-505 — WorkOS Integration - Admin Settings - Users tab settings do not save

Problem

On WorkOS → Settings → Users, clicking Save Settings did nothing and no changes persisted (logout redirects, deprovision action, reassign user, role map — all silently dropped).

Root cause

The Users tab is wrapped in the WordPress Settings API form:

<form action="options.php" method="post">
    settings_fields( 'workos_settings' );
    do_settings_sections( 'workos-users' );  // renders all sections
    submit_button( 'Save Settings' );        // the Save button
</form>

render_role_map() (the last section) emitted its own <form> for the "Sync Roles to WorkOS" button — nested inside that outer form. Browsers don't allow nested forms: the HTML parser ignores the inner <form> open tag but honors its </form>, which closes the outer settings form early. Because Role Mapping is the last section, the submit_button() that follows ends up outside the form, so clicking it submits nothing and options.php never runs.

This is the same class of bug as the earlier "unnest Create Organization modal so settings save works" fix (#6) — that one was missed on the role-sync form. Only the Users tab was affected (the other tabs have no nested form), and only when the plugin is enabled with an org configured (the condition that renders the sync button).

Fix

Mirror the existing modal pattern:

  • Defer the sync <form> to admin_footer so it sits at body level, not nested in the settings form (render_role_sync_form()).
  • Keep the visible "Sync Roles to WorkOS" button in the actions row, wired to that form via the HTML5 form="workos-role-sync-form" attribute.

The settings form stays intact; Save works. The role-map JS still finds the settings form via table.closest('form'), so its duplicate-role submit guard keeps working.

Testing

  • Verified locally (Lando): on the Users tab, changing a logout redirect / deprovision action / role mapping and clicking Save Settings now persists across a refresh. Confirmed the "Sync Roles to WorkOS" button still submits to admin-post.php via the footer form.
  • php -l clean.

🤖 Generated with Claude Code

The "Sync Roles to WorkOS" button rendered its own <form> inside the
Settings API options.php form on the Users tab. Nested forms are invalid
HTML — the inner </form> closes the outer form early, and because Role
Mapping is the last section, the "Save Settings" submit button ends up
outside the form. Result: clicking Save did nothing and no Users-tab
settings (logout redirects, deprovision action, role map) persisted.

Defer the sync form to admin_footer (body level, mirroring the existing
Create Organization modal fix) and wire its button back via the HTML5
`form` attribute. The settings form stays intact and saves normally.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@skyshab skyshab self-assigned this Jun 9, 2026
@skyshab skyshab changed the title fix(admin): unnest Sync Roles form so Users settings save [CONS-505] fix(admin): unnest Sync Roles form so Users settings save Jun 9, 2026
@skyshab
skyshab requested a review from bordoni June 9, 2026 17:13
@bordoni bordoni added this to the 1.0.6 milestone Jun 9, 2026
@bordoni
bordoni merged commit 4f80489 into main Jun 9, 2026
7 checks passed
@bordoni
bordoni deleted the fix/users-settings-nested-form-save branch June 9, 2026 20:03
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.

2 participants