You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make the Visual Styler preview match the front end - #3701
The Visual Styler preview sits inside wp-admin, so admin CSS reached into it and the theme CSS never did. A field could look noticeably different in the styler than on the live form. Comparing computed styles between the styler preview and the in-theme preview for the same form and style, this takes the number of differing properties from 397 to 26. Most of what remains depends on front end JavaScript that the preview does not load (intl-tel phone input, SlimSelect, range fill).
What changed
Formidable admin CSS no longer applies inside the preview. About 120 selectors in resources/scss/admin (fonts, paragraphs, headings, links, labels, descriptions, radios and checkboxes, field widths and margins) get :where(:not(#frm_style_preview *)) through a new $outside-styler-preview SCSS variable. :where() keeps their specificity unchanged everywhere else, so the builder and settings pages are unaffected.
This fixes the label padding setting in the preview. The admin .frm_form_field > label:first-child { padding: 0 } rule overrode --label-padding, so that setting never showed in the styler.
New css/admin/styler-preview.css undoes the wp-admin element styles from common.css and forms.css inside the preview. Each rule mirrors the wp-admin selector inside @scope and sets revert, so it beats the wp-admin rule but not Formidable style rules or the theme.
The active theme's front end CSS is loaded into the preview, scoped with @scope to #frm_active_style_form, #frm_sample_form. New FrmStylesThemeCssHelper collects the theme's enqueued stylesheets plus the global stylesheet, rewrites html/body/:root selectors and rem lengths, and hoists @font-face and @keyframes. It is ported from the Views PR above, with the scope passed in so Views can reuse it. It is served from a new frm_styler_theme_css AJAX action, cached in a transient, and can be turned off with the new frm_styler_load_theme_css filter. Browsers without @scope support ignore the block, so the preview looks the way it does today.
Removed css/admin/style.css overrides that made the preview differ on purpose: the dashicon select arrow, appearance: none on selects, and the label and checkbox overrides that only existed to fight admin CSS.
Faster styler loads. The styler's copy of the saved stylesheet (frmpro_css, over 1 MB on sites with many styles) and the theme CSS are now browser-cacheable. Their URL versions change on any style save, global custom CSS edit, or theme or Global Styles change. Both end their response with die() rather than wp_die(), because the AJAX wp_die() handler re-sends no-cache headers.
js/admin/style.js cancels an outdated preview request when a newer one starts, so dragging a slider no longer queues up requests.
Notes
A theme rule that is less specific than a wp-admin selector, like * { box-sizing: border-box; }, loses to the reset. Settings where the wp-admin value matches what nearly every theme does are therefore not reset. Small known leftovers: radio line-height, a 3px radio margin, and the 10px form padding the styler adds on purpose.
Tested with a classic theme (hello-elementor). Block themes go through the same global stylesheet path but were not tested.
css/frm_testing_mode.css changes only because it shares the button SCSS. The added selector never matches outside the styler.
Testing
Activate a theme with a distinctive body font and form element styles.
Open Formidable > Styles > edit a style, with a form that has text, select, radio, checkbox, HTML and description content.
Compare the preview with the same form on a front end page. Fonts, base text size and color, headings, paragraphs, label spacing, select arrows and radio and checkbox styling should now match.
Change the style's label padding. The preview label should move. Before this change it did not.
Check that the styler sidebar, the form builder and the global settings pages look unchanged.
Reload the styler. In the network panel, the frmpro_css and frm_styler_theme_css requests should come from the browser cache. Save the style, reload, and both should download again.
Add add_filter( 'frm_styler_load_theme_css', '__return_false' ); and confirm the preview loads without the theme CSS.
Keep admin CSS out of the Visual Styler preview so a form looks the
same there as on the live site. Formidable admin rules that reached
into the preview now skip it, and a scoped reset undoes the wp-admin
element styles. This also lets the label padding setting show in the
preview, which an admin rule used to zero.
Load the active theme's front end CSS into the preview, scoped with
@scope so it cannot leak into the rest of wp-admin. It can be turned
off with the frm_styler_load_theme_css filter.
Let the browser cache the styler's versioned stylesheets, and cancel
an outdated preview request when a newer one starts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
We reviewed changes in ab4ee48...b02ea6c on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.
AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.
The reason will be displayed to describe this comment to others. Learn more.
Use of insecure md5() function found
Using md5(), sha1() function is not recommended to generate secure passwords. Due to its fast nature to compute passwords too quickly, these functions can become really easy to crack a password using brute force attack.
It is recommended to use PHP's password hashing function password_hash() to create a secure password hash.
The reason will be displayed to describe this comment to others. Learn more.
Use of insecure md5() function found
Using md5(), sha1() function is not recommended to generate secure passwords. Due to its fast nature to compute passwords too quickly, these functions can become really easy to crack a password using brute force attack.
It is recommended to use PHP's password hashing function password_hash() to create a secure password hash.
The reason will be displayed to describe this comment to others. Learn more.
Use of insecure md5() function found
Using md5(), sha1() function is not recommended to generate secure passwords. Due to its fast nature to compute passwords too quickly, these functions can become really easy to crack a password using brute force attack.
It is recommended to use PHP's password hashing function password_hash() to create a secure password hash.
The reason will be displayed to describe this comment to others. Learn more.
`split_rules` has a cyclomatic complexity of 21 with "High" risk
A function with high cyclomatic complexity can be hard to understand and
maintain. Cyclomatic complexity is a software metric that measures the number of
independent paths through a function. A higher cyclomatic complexity indicates
that the function has more decision points and is more complex.
Require the frm_ajax nonce, as the other styler AJAX actions do,
before serving the theme CSS for the preview.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reason will be displayed to describe this comment to others. Learn more.
Request changes. I ran this on the PR head (68e86cc) in the Formidable preview env with the block theme Twenty Twenty-Five.
What works (live): I compared computed styles of the same form (text, textarea, label, description, submit) on a front-end page and in the Visual Styler. On master the preview differed from the front end on 12 properties (font family on every control, label line-height / letter-spacing / bottom margin vs padding, textarea line-height, description line-height, submit font). On this head there were 0 differences. The label-padding claim holds: the master preview shows label padding-bottom: 0 and margin-bottom: 6px where the front end has 5px padding. The new frm_styler_theme_css endpoint returns the scoped CSS (200, 27 KB), is capability- and nonce-gated, and both stylesheets go out with the private, max-age=31536000, immutable header. Builder and styler sidebar still render normally (screenshots checked). Security pass by hand: the endpoint reads theme files only and echoes no request input; nothing exploitable found.
Blocking
FrmStylesThemeCssHelper.php:774: conditional html.x / body.x rules become unconditional :scope rules, so a dark-mode or page-specific theme rule leaks into every preview (reproduced, see inline).
FrmStylesThemeCssHelper.php:388: the url() rewrite breaks on parentheses in data URIs and can corrupt the rules after it (reproduced, see inline).
No tests. This adds a 934-line CSS rewriter with no PHPUnit coverage; tests/phpunit/styles/ has the neighbouring tests. The two bugs above are what a table-driven test over rewrite_selector_list(), absolutize_urls() and rewrite_rules() would have caught.
Non-blocking
Cache/version issues, see the inline note at FrmStylesController.php:224.
Theme-root matching at FrmStylesThemeCssHelper.php:228 uses str_starts_with() on a root URL with no trailing slash, so .../themes/twentytwenty also matches .../themes/twentytwentyone/.... Compare against $root['url'] . '/'.
do_action( 'wp_enqueue_scripts' ) runs every plugin's front-end enqueue callbacks inside an admin-ajax request. The try/catch covers exceptions and errors, not exit. Fine to keep, but worth a note in the docblock.
Tests run:php -l on both PHP files and node --check js/admin/style.js are clean. The helper reproductions above were run directly against the PR's code. PHPUnit, PHPCS, PHPStan and Stylelint were not run by me, and CI shows most of those jobs as skipping on this head (only Psalm, Typos, DeepScan and Scrutinizer ran and passed; DeepSource PHP failed), so the PR currently has no lint or unit run at all. Not tested: block-theme theme.json edge cases beyond TT25, classic theme (PR says hello-elementor was tested), and the "from browser cache" network-panel check (verified through the response headers instead).
The reason will be displayed to describe this comment to others. Learn more.
Blocking: html/body selectors lose their class, attribute and :not() conditions, so conditional theme rules apply unconditionally in the preview.
rewrite_selector() strips everything after html / body / :root that is a class, attribute or pseudo (the second and third preg_replace). A rule that only applies on the front end under a condition becomes an always-on rule. Reproduced on this head with the helper's own methods:
So a theme with a body.dark-mode { color:#fff } (or body.home, body.logged-in, html.no-js ...) block makes the styler preview render white text, while the real form (no such class on the page) does not. That is the opposite of what this PR is for.
Fix: only rewrite a bare html / body / :root (optionally followed by a combinator). If the compound has a class, attribute, id or :not()/:is()/:has() condition, drop the whole selector from the list (the preview container never carries those classes), not just the condition. Add a test per case above.
in : .b{background:url("data:image/svg+xml,%3Csvg(1)")}
out: .b{background:url("data:image/svg+xml,%3Csvg(1")")}
The stray ") leaves an unterminated string, and a browser's error recovery can then drop the following declarations or rules, so the damage is not limited to that one property. Themes use url("data:image/svg+xml,...rgb(...)...") for select arrows and checkmarks all the time, which is exactly what the styler preview shows.
Fix: match quoted values first, e.g. /url\(\s*(?:"([^"]*)"|'([^']*)'|([^)\s]+))\s*\)/i, and leave data:, #fragment and already-absolute values untouched (check that absolutize_url() does). Add a test with a quoted data URI containing parentheses.
The reason will be displayed to describe this comment to others. Learn more.
Non-blocking: an empty result is cached for a day, and the version key misses real inputs.
get_scoped_theme_css() returns '' when the theme exposes no readable CSS or the sandboxed enqueue throws. is_string( '' ) is true, so set_transient() stores it and every request for the next 24h gets an empty sheet. Consider not caching an empty string.
FrmStylesThemeCssHelper::get_version() is built from the theme slug, the theme's Version header and a hash of wp_get_global_stylesheet(). Editing a classic theme's style.css without a version bump, or anything added through frm_preview_theme_stylesheets or a plugin's wp_enqueue_scripts, leaves the key unchanged. The transient then serves the old CSS for a day, and the immutable header keeps the browser copy too. The docblock also says a Customizer edit changes the version; only the Global Styles part does. Consider adding the stylesheet files' filemtime() to the version.
The preview alignment rules now target only fields that inherit the
style layout, plus the sample form. A field with its own layout no
longer gets overridden when an unrelated style setting changes.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_radio {', $css, 'An unrelated setting must not override a radio layout exception.' );
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_checkbox {', $css, 'An unrelated setting must not override a checkbox layout exception.' );
$this->assertStringContainsString( '.frm-default-option-align .frm_radio', $css, 'Inherited radio layouts should still follow the style.' );
$this->assertStringContainsString( '.frm-default-option-align .frm_checkbox', $css, 'Inherited checkbox layouts should still follow the style.' );
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_radio {', $css, 'An unrelated setting must not override a radio layout exception.' );
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_checkbox {', $css, 'An unrelated setting must not override a checkbox layout exception.' );
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_radio {', $css, 'An unrelated setting must not override a radio layout exception.' );
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_checkbox {', $css, 'An unrelated setting must not override a checkbox layout exception.' );
$this->assertStringContainsString( '.frm-default-option-align .frm_radio', $css, 'Inherited radio layouts should still follow the style.' );
$this->assertStringNotContainsString( '#frm_style_preview .with_frm_style .frm_radio {', $css, 'An unrelated setting must not override a radio layout exception.' );
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: https://github.com/Strategy11/formidable-views/pull/745 (same theme CSS approach, for the View editor)
The Visual Styler preview sits inside wp-admin, so admin CSS reached into it and the theme CSS never did. A field could look noticeably different in the styler than on the live form. Comparing computed styles between the styler preview and the in-theme preview for the same form and style, this takes the number of differing properties from 397 to 26. Most of what remains depends on front end JavaScript that the preview does not load (intl-tel phone input, SlimSelect, range fill).
What changed
resources/scss/admin(fonts, paragraphs, headings, links, labels, descriptions, radios and checkboxes, field widths and margins) get:where(:not(#frm_style_preview *))through a new$outside-styler-previewSCSS variable.:where()keeps their specificity unchanged everywhere else, so the builder and settings pages are unaffected..frm_form_field > label:first-child { padding: 0 }rule overrode--label-padding, so that setting never showed in the styler.css/admin/styler-preview.cssundoes the wp-admin element styles fromcommon.cssandforms.cssinside the preview. Each rule mirrors the wp-admin selector inside@scopeand setsrevert, so it beats the wp-admin rule but not Formidable style rules or the theme.@scopeto#frm_active_style_form, #frm_sample_form. NewFrmStylesThemeCssHelpercollects the theme's enqueued stylesheets plus the global stylesheet, rewriteshtml/body/:rootselectors and rem lengths, and hoists@font-faceand@keyframes. It is ported from the Views PR above, with the scope passed in so Views can reuse it. It is served from a newfrm_styler_theme_cssAJAX action, cached in a transient, and can be turned off with the newfrm_styler_load_theme_cssfilter. Browsers without@scopesupport ignore the block, so the preview looks the way it does today.css/admin/style.cssoverrides that made the preview differ on purpose: the dashicon select arrow,appearance: noneon selects, and the label and checkbox overrides that only existed to fight admin CSS.frmpro_css, over 1 MB on sites with many styles) and the theme CSS are now browser-cacheable. Their URL versions change on any style save, global custom CSS edit, or theme or Global Styles change. Both end their response withdie()rather thanwp_die(), because the AJAXwp_die()handler re-sends no-cache headers.js/admin/style.jscancels an outdated preview request when a newer one starts, so dragging a slider no longer queues up requests.Notes
* { box-sizing: border-box; }, loses to the reset. Settings where the wp-admin value matches what nearly every theme does are therefore not reset. Small known leftovers: radio line-height, a 3px radio margin, and the 10px form padding the styler adds on purpose.css/frm_testing_mode.csschanges only because it shares the button SCSS. The added selector never matches outside the styler.Testing
frmpro_cssandfrm_styler_theme_cssrequests should come from the browser cache. Save the style, reload, and both should download again.add_filter( 'frm_styler_load_theme_css', '__return_false' );and confirm the preview loads without the theme CSS.🤖 Generated with Claude Code