Skip to content

show css vars for fields values that are changed later via css_var_prepare_value#2456

Closed
Liviu-p wants to merge 1 commit into
masterfrom
issuesfix-style-custom-theme/style-border-width
Closed

show css vars for fields values that are changed later via css_var_prepare_value#2456
Liviu-p wants to merge 1 commit into
masterfrom
issuesfix-style-custom-theme/style-border-width

Conversation

@Liviu-p
Copy link
Copy Markdown
Contributor

@Liviu-p Liviu-p commented Aug 8, 2025

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Aug 8, 2025

Walkthrough

The output_vars method in FrmStylesHelper.php was updated to always output CSS variables for specific fields, regardless of whether their values match defaults. This ensures that variables for fields like border width and font are included in the output, even if their settings have not changed from defaults.

Changes

Cohort / File(s) Change Summary
FrmStylesHelper output_vars logic
classes/helpers/FrmStylesHelper.php
Modified the conditional logic in output_vars to always output CSS variables for certain fields, ensuring their presence even if their values match defaults. No changes to method signatures or public interfaces.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

  • Stop outputting field shape type as css var #2328: Both PRs adjust the logic in output_vars to control which CSS variables are output, with this PR adding always-output conditions and the related PR excluding a specific field.
  • Do not output invalid css vars #2296: Both PRs modify validation and filtering in output_vars, but this PR focuses on always including certain fields, while the related PR enhances validation for all variables.

Suggested labels

run analysis, run tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 PHPStan (2.1.17)

Note: Using configuration file /phpstan.neon.
Invalid configuration:
Unexpected item 'parameters › strictRules'.

Note

🔌 MCP (Model Context Protocol) integration is now available in Early Access!

Pro users can now connect to remote MCP servers under the Integrations page to get reviews and chat conversations that understand additional development context.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch issuesfix-style-custom-theme/style-border-width

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (3)
classes/helpers/FrmStylesHelper.php (3)

446-450: Avoid rebuilding $show_fields on each iteration

Minor perf/readability win: make it static within the method so it’s allocated once per request.

Apply:

-			// These fields value may be changed later in css_var_prepare_value() as $settings[ $var ] will be the same as $defaults[ $var ] and the condition will be false
-			$show_fields = array( 'field_border_width', 'border_radius', 'border_width_error', 'box_shadow', 'font' );
+			// These fields' values may be changed later in css_var_prepare_value(), even when $settings[ $var ] === $defaults[ $var ].
+			static $show_fields = array( 'field_border_width', 'border_radius', 'border_width_error', 'box_shadow', 'font' );

446-450: Validate and echo the prepared value, not the raw setting (optional hardening)

Right now the validity check uses the raw $settings[ $var ]. In edge cases, css_var_prepare_value() can sanitize/normalize a value into a safe one that fails the raw check. Consider:

  • Compute $prepared = self::css_var_prepare_value( $settings, $var )
  • Validate $prepared with css_value_is_valid()
  • Echo $prepared

For clarity (non-diff, spans adjacent lines):

$prepared = self::css_var_prepare_value( $settings, $var );
if ( $show && self::css_value_is_valid( $prepared ) ) {
	echo '--' . esc_html( self::clean_var_name( str_replace( '_', '-', $var ) ) ) . ':' . $prepared . ';'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
}

447-449: Comment grammar/clarity

Tighten the comment.

Apply:

-			// These fields value may be changed later in css_var_prepare_value() as $settings[ $var ] will be the same as $defaults[ $var ] and the condition will be false
+			// These fields' values may be changed later in css_var_prepare_value(), even when $settings[ $var ] === $defaults[ $var ].
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02d6462 and ea512a6.

📒 Files selected for processing (1)
  • classes/helpers/FrmStylesHelper.php (1 hunks)
🔇 Additional comments (1)
classes/helpers/FrmStylesHelper.php (1)

446-450: Correct: always emit CSS vars for values transformed in css_var_prepare_value

This directly addresses the PR goal. The list covers all keys that css_var_prepare_value can change independently of defaults (font, field_border_width, border_width_error, box_shadow, border_radius). Behavior for other keys remains unchanged.

Comment thread classes/helpers/FrmStylesHelper.php
@Crabcyborg
Copy link
Copy Markdown
Contributor

@Liviu-p What do you think about #2482 instead?

@Crabcyborg
Copy link
Copy Markdown
Contributor

Closing this since #2482 covers the issue.

@Crabcyborg Crabcyborg closed this Aug 29, 2025
@Crabcyborg Crabcyborg deleted the issuesfix-style-custom-theme/style-border-width branch August 29, 2025 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants