Skip to content

fix(forms): modernize CSS themes with :where() zero-specificity reset#848

Open
faisalahammad wants to merge 1 commit into
ibericode:mainfrom
faisalahammad:fix/844-modernize-form-css
Open

fix(forms): modernize CSS themes with :where() zero-specificity reset#848
faisalahammad wants to merge 1 commit into
ibericode:mainfrom
faisalahammad:fix/844-modernize-form-css

Conversation

@faisalahammad
Copy link
Copy Markdown
Contributor

@faisalahammad faisalahammad commented May 31, 2026

Summary

Replace the 5 opinionated color themes (light/dark/red/blue/green) with a minimal :where() CSS reset that uses zero specificity — themes and plugins always override without fighting specificity wars. Reduces CSS from ~320 lines to ~48.

Fixes #844

Changes

assets/src/css/form-basic.css

Before:

/* ~122 lines with high-specificity selectors */
.mc4wp-form { ... }
.mc4wp-form label { ... }
.mc4wp-form input[type="text"] { ... }

After:

/* ~48 lines with zero-specificity :where() selectors */
:where(.mc4wp-form) { margin: 1em 0; }
:where(.mc4wp-form label) { display: block; font-weight: bold; margin-bottom: 6px; }
:where(.mc4wp-form input[type="submit"]) { cursor: pointer; display: inline-block; appearance: none; }
/* Alert colors stay at normal specificity (functional) */
.mc4wp-alert { color: #c09853; }
.mc4wp-error { color: #cd5c5c; }

Why: :where() always has specificity 0, so theme CSS wins without !important. Honeypot hiding uses normal specificity (must not be overridable). CSS logical properties (margin-inline-end) replace directional rules for native RTL support.

assets/src/css/form-themes.css

Deprecated — contains only a comment. Minified output is 0 bytes.

includes/admin/migrations/5.0.0-modernize-css.php

New file. Converts all mc4wp-form posts with theme-* CSS setting to basic, rebuilds mc4wp_form_stylesheets option without themes.

Why: Existing forms using color themes need migration to avoid broken references.

includes/forms/class-form.php

Before:

public function get_stylesheet() {
    $stylesheet = $this->settings['css'];
    if (empty($stylesheet)) { return ''; }
    return $stylesheet;  // theme-* returned as-is → no CSS loads
}

After:

public function get_stylesheet() {
    $stylesheet = $this->settings['css'];
    if (empty($stylesheet)) { return ''; }
    if (strpos($stylesheet, 'theme-') === 0) { return 'basic'; }  // safety net
    return $stylesheet;
}

Why: Un-migrated forms (e.g. fresh zip install without running migration) still work — theme-* values silently fall back to basic.

includes/forms/class-form-element.php

Removed mc4wp-form-theme class generation block.

includes/forms/class-asset-manager.php

Removed 'themes' from get_registered_stylesheets() — now returns only ['basic'].

includes/forms/views/tabs/form-appearance.php

Removed 5 color theme <option> entries from the CSS dropdown. Only "Inherit" and "Basic" remain. mc4wp_admin_form_css_options filter preserved for third-party use.

tests/FormTest.php

Added assertions for theme-*basic fallback and custom stylesheet passthrough.

Testing

Test 1: Basic CSS renders correctly

  1. Create/edit form → Appearance tab → set CSS to "Basic (minimal reset)"
  2. View form on frontend

Result: Inputs layout correctly, no forced colors/borders.

Test 2: Inherit option works

  1. Set form CSS to "Inherit from [theme]"
  2. View on frontend

Result: Form uses active WP theme styles.

Test 3: Existing theme- forms migrated*

  1. Install plugin on site with forms using color themes
  2. Check form editor → Appearance tab

Result: "Basic" selected. Frontend renders with basic reset.

Test 4: Admin UI simplified

  1. Form editor → Appearance tab

Result: Dropdown shows only "Inherit" and "Basic" options.

Test 5: RTL checkbox spacing

  1. View form with checkboxes in RTL language (Arabic)

Result: Checkbox margin on correct side (margin-inline-end).

Replace heavy opinionated color themes (light/dark/red/blue/green) with minimal
:where() CSS reset that has zero specificity — themes and plugins always win.

- Rewrite form-basic.css with :where() selectors (~48 lines vs ~320)
- Remove form-themes.css content (deprecated placeholder)
- Remove theme options from admin UI (only Inherit + Basic remain)
- Add migration 5.0.0 to convert theme-* selections to basic
- Add defensive theme-* fallback in get_stylesheet()
- Remove mc4wp-form-theme class generation
- Use CSS logical properties for RTL support
- Keep alert color classes at normal specificity (functional)

Fixes ibericode#844
@faisalahammad faisalahammad force-pushed the fix/844-modernize-form-css branch from 38cbb64 to feb077f Compare May 31, 2026 13:49
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.

Modernize form CSS themes

1 participant