Skip to content

Stop printing global custom css when single style custom css is not set#2703

Merged
Crabcyborg merged 2 commits into
masterfrom
stop_printing_global_custom_css_when_single_style_custom_css_is_not_set
Jan 2, 2026
Merged

Stop printing global custom css when single style custom css is not set#2703
Crabcyborg merged 2 commits into
masterfrom
stop_printing_global_custom_css_when_single_style_custom_css_is_not_set

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 2, 2026

Walkthrough

The changes add defensive null-checking to the get_custom_css method to verify key presence before returning values, and optimize variable assignments in the CSS template by using null-coalescing operators to avoid redundant function call re-evaluations.

Changes

Cohort / File(s) Summary
Custom CSS Key Validation
classes/controllers/FrmStylesController.php
Modified get_custom_css to verify presence of single_style_custom_css and enable_style_custom_css keys before returning; returns empty string if keys absent, preventing potential undefined key access.
Variable Initialization Optimization
css/_single_theme.css.php
Changed $use_chosen_js and $pro_is_installed assignments to use null-coalescing operator (??) to preserve existing values and avoid redundant helper function calls if variables already defined.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • PR #2600: Modifies FrmStylesController::get_custom_css with similar handling of $single_style_settings parameter and related custom CSS key validation logic.
  • PR #2701: Updates css/_single_theme.css.php with changes to $pro_is_installed handling and Pro-only CSS conditional output logic.
  • PR #2128: Modifies css/_single_theme.css.php and includes updates to CSS output logic involving use_chosen_js variable handling.

Suggested reviewers

  • lauramekaj1

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to evaluate whether any description content relates to the changeset. Add a pull request description explaining the motivation, impact, and context of the changes, even if brief.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: preventing global custom CSS from being printed when single style custom CSS is not set, which aligns with the primary modification in FrmStylesController.php.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings

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

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 0

🧹 Nitpick comments (1)
classes/controllers/FrmStylesController.php (1)

869-872: Enhance parameter documentation.

The $single_style_settings parameter should document the expected array structure, specifically that it should contain single_style_custom_css and enable_style_custom_css keys.

🔎 Suggested documentation improvement
 	/**
 	 * Get custom CSS code entered in the Custom CSS page.
 	 *
 	 * @since 6.0
 	 *
-	 * @param array|null $single_style_settings The single style settings.
+	 * @param array|null $single_style_settings {
+	 *     Optional. The single style settings array.
+	 *
+	 *     @type string $single_style_custom_css  Custom CSS for the single style.
+	 *     @type bool   $enable_style_custom_css  Whether custom CSS is enabled.
+	 * }
 	 *
 	 * @return string
 	 */
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8e0b2ef and 4f5acdd.

📒 Files selected for processing (2)
  • classes/controllers/FrmStylesController.php
  • css/_single_theme.css.php
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: PHP 8 tests in WP 6.9
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: Cypress
  • GitHub Check: PHP 7.4 tests in WP 6.9
  • GitHub Check: Cypress
  • GitHub Check: PHP 8 tests in WP 6.9
🔇 Additional comments (2)
css/_single_theme.css.php (1)

16-17: LGTM - Good optimization using null-coalescing.

The null-coalescing operators correctly avoid re-evaluating helper functions if these variables are already defined via the extract($settings) on line 7. This optimization prevents redundant function calls while maintaining the same functionality.

classes/controllers/FrmStylesController.php (1)

874-880: Behavior change is intentional and safe.

The new logic requiring BOTH single_style_custom_css AND enable_style_custom_css correctly implements the feature. This change only affects the single-style-specific CSS rendering path (called in _single_theme.css.php). Global CSS calls in custom_theme.css.php and FrmStylesController.php bypass this logic entirely and continue to use the default settings. Since enable_style_custom_css defaults to false and the UI controls visibility of the CSS editor with a toggle, the change safely enforces user intent without breaking existing functionality.

@Crabcyborg Crabcyborg merged commit 2815bc7 into master Jan 2, 2026
36 checks passed
@Crabcyborg Crabcyborg deleted the stop_printing_global_custom_css_when_single_style_custom_css_is_not_set branch January 2, 2026 20:41
stephywells pushed a commit that referenced this pull request Apr 4, 2026
…css_when_single_style_custom_css_is_not_set

Stop printing global custom css when single style custom css is not set
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.

1 participant