Skip to content

fix(bricks): skip color-palette injection on Bricks 2.2+ Color Manager - #182

Merged
jackgranatowski merged 2 commits into
mainfrom
devin/1780302974-bricks-22-colormanager-darkmode
Jun 1, 2026
Merged

fix(bricks): skip color-palette injection on Bricks 2.2+ Color Manager#182
jackgranatowski merged 2 commits into
mainfrom
devin/1780302974-bricks-22-colormanager-darkmode

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Dark/light mode silently breaks for SLASHED colors in Bricks 2.2+. Bricks 2.2's new Color Manager materializes every color-palette entry into :root as a static value (plus a [data-brx-theme="dark"] variant). When the plugin injects the SLASHED palette, Bricks bakes each token to fixed hex on :root, which overrides the framework's adaptive light-dark() --sf-color-* definitions. Worse, the injected dark_mode hex equals the light hex (added in 50dcfeb), so the dark :root block is identical to light — the toggle flips color-scheme/data-brx-theme but var(--sf-color-primary) never changes.

Observed in a user export (unlayered, so it beats every @layer):

:root                       { --sf-color-primary:#fe6a00; … }
:root[data-brx-theme="dark"]{ --sf-color-primary:#fe6a00; … }  /* same hex */
#brxe-fvcxsu { background-color: var(--sf-color-primary) }       /* frozen */

Fix: on Bricks 2.2+, don't inject SLASHED palettes into bricks_color_palette. Tokens stay reachable via the Variable Manager (class-variables.php), whose empty-value entries Bricks never writes to :root, so the framework remains the single source of truth and light-dark() drives theming again. Pre-2.2 behavior is unchanged.

Changes

  • slashed-bricks.php: new slashed_bricks_supports_color_manager(). Resolves the Bricks version (BRICKS_VERSION, else theme version) and compares on major.minor (>= 2.2) — version_compare() ranks 2.2-beta below 2.2, which would miss the beta where the Color Manager first shipped.
  • class-colors.php: inject_palettes() now early-returns (after the usual strip) when should_inject_palettes() is false. Default = ! supports_color_manager, overridable via the new slashed_bricks/inject_color_palette filter (__return_true to force injection on 2.2+, accepting static hex snapshots without dark-mode adaptation). The version check runs inside the filter (not the constructor) because BRICKS_VERSION isn't defined yet at plugins_loaded, where the managers are instantiated. strip_palettes still runs on save to clean any stale rows.
  • README.md: documents the 2.2 behavior + the new filter.

Testing

  • php -l clean on both changed files.
  • Logic harness over the gating: 1.9.2/2.1.5 → inject; 2.2, 2.2.0, 2.2-beta, 2.2.1-RC1, 2.3.1, 2.10, 3.0 → skip; empty/garbage → inject (safe pre-2.2 default); slashed_bricks/inject_color_palette override → inject. All pass.
  • Not verified on a live Bricks 2.2 install (no WP/Bricks env here) — please confirm on a 2.2 site: :root should no longer hardcode --sf-color-primary, and its computed value should be an oklch(...) that differs between data-brx-theme="light" and "dark".

Follow-up

Restoring color swatches in the 2.2 Color Manager without breaking adaptivity (e.g. injecting real distinct light/dark hex, or a Color-Manager-native registration) is left as a QoL follow-up; the Variable picker already previews tokens on the canvas.

Link to Devin session: https://app.devin.ai/sessions/113c6a747fc6406c9510e0e88892441f
Requested by: @jackgranatowski

Summary by CodeRabbit

Release Notes

  • Documentation

    • Updated Bricks integration documentation with detailed clarification on color palette injection behavior with Bricks 2.2+ Color Manager and override options.
  • New Features

    • Added a new filter hook enabling custom control over color palette injection behavior with Bricks, including usage examples.

Bricks 2.2's Color Manager materializes every color-palette entry into :root as a static value (plus a [data-brx-theme="dark"] variant), which overrides the framework's adaptive light-dark() --sf-color-* tokens and freezes dark/light switching. Because the plugin injects the palette and the dark_mode hex equals the light hex, the section bg renders the same color in both modes.

On Bricks 2.2+ skip palette injection (slashed_bricks_supports_color_manager(), gated by the slashed_bricks/inject_color_palette filter); tokens remain available via the Variable Manager, which registers empty-value entries Bricks never writes to :root. Version is compared on major.minor so 2.2 pre-release builds are detected.

Co-Authored-By: Jack Granatowski <jack.granatowski@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@jackgranatowski

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 55a7578c-9b19-4e59-b0c4-da7a62430aa1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added a version detection helper to identify Bricks 2.2+ Color Manager support, made palette injection conditional on that detection via a new guard method, and exposed a filter hook to override injection behavior. Documented the gating logic, filter usage, and architectural rationale in the README.

Changes

Color Manager Support Detection and Conditional Palette Injection

Layer / File(s) Summary
Version detection helper
plugins/SLASHED-for-WP/integrations/bricks/slashed-bricks.php
New slashed_bricks_supports_color_manager() function detects Bricks 2.2+ by reading BRICKS_VERSION constant or theme metadata, validates format, and returns boolean based on major/minor version comparison.
Conditional injection logic
plugins/SLASHED-for-WP/integrations/bricks/includes/class-colors.php
Private should_inject_palettes() method checks Color Manager support and applies slashed_bricks/inject_color_palette filter to gate injection; inject_palettes() calls the guard and returns unchanged palette array when injection is skipped.
Documentation
plugins/SLASHED-for-WP/integrations/bricks/README.md
Updated feature description, added filter documentation with override example, and inserted architecture notes explaining Color Manager incompatibility and how to force palette injection on Bricks 2.2+.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • codeslash-dev/SLASHED#71: Extends the initial Bricks color injection implementation by adding version detection and a conditional filter for Color Manager support gating.
  • codeslash-dev/SLASHED#81: Both PRs modify the Bricks color integration in class-colors.php—one refactors palette generation while this one conditionally gates injection based on Color Manager support.
  • codeslash-dev/SLASHED#176: Both PRs adjust how SLASHED palette/color data works with Bricks Color Manager via changes to class-colors.php.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(bricks): skip color-palette injection on Bricks 2.2+ Color Manager' accurately and specifically describes the main change: conditional skipping of palette injection for Bricks 2.2+ to fix Color Manager incompatibility.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch devin/1780302974-bricks-22-colormanager-darkmode

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
plugins/SLASHED-for-WP/integrations/bricks/slashed-bricks.php (1)

151-178: ⚡ Quick win

Version gating logic is correct; consider extracting the shared version-resolution block.

The major.minor comparison correctly catches pre-release 2.2-* builds that version_compare() would rank below 2.2. Edge cases check out (2.10 → true, 2.1.5 → false, 3.0 → true).

The BRICKS_VERSION/theme-metadata resolution in Lines 154-165 duplicates the same block in slashed_bricks_is_bricks_active() (Lines 119-131). Extracting a small slashed_bricks_get_bricks_version() helper keeps both detectors in sync if Bricks ever changes how its version is exposed.

♻️ Proposed extraction
/**
 * Resolve the active Bricks version string, or '' if unknown.
 *
 * `@return` string
 */
function slashed_bricks_get_bricks_version() {
    if ( defined( 'BRICKS_VERSION' ) ) {
        return (string) BRICKS_VERSION;
    }

    $theme = wp_get_theme();

    if ( 'bricks' === strtolower( $theme->get_template() ) ) {
        $parent = $theme->parent();
        return $parent ? (string) $parent->get( 'Version' ) : (string) $theme->get( 'Version' );
    }

    if ( 'bricks' === strtolower( $theme->get( 'Name' ) ) ) {
        return (string) $theme->get( 'Version' );
    }

    return '';
}

Then slashed_bricks_supports_color_manager() becomes:

 function slashed_bricks_supports_color_manager() {
-    $version = '';
-
-    if ( defined( 'BRICKS_VERSION' ) ) {
-        $version = (string) BRICKS_VERSION;
-    } else {
-        $theme = wp_get_theme();
-
-        if ( 'bricks' === strtolower( $theme->get_template() ) ) {
-            $parent  = $theme->parent();
-            $version = $parent ? (string) $parent->get( 'Version' ) : (string) $theme->get( 'Version' );
-        } elseif ( 'bricks' === strtolower( $theme->get( 'Name' ) ) ) {
-            $version = (string) $theme->get( 'Version' );
-        }
-    }
-
+    $version = slashed_bricks_get_bricks_version();
     if ( '' === $version || ! preg_match( '/^(\d+)\.(\d+)/', $version, $m ) ) {
         return false;
     }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@plugins/SLASHED-for-WP/integrations/bricks/slashed-bricks.php` around lines
151 - 178, Extract the duplicated BRICKS_VERSION/theme metadata resolution into
a new helper slashed_bricks_get_bricks_version() that returns the Bricks version
string or '' and replace the inline resolution in both
slashed_bricks_supports_color_manager() and slashed_bricks_is_bricks_active()
with calls to that helper; ensure the helper implements the same logic currently
used (check defined('BRICKS_VERSION'), then wp_get_theme() and compare
strtolower($theme->get_template()) and strtolower($theme->get('Name')) and
return parent or theme Version as appropriate) so both callers get the same
canonical version string for the existing major/minor comparison.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@plugins/SLASHED-for-WP/integrations/bricks/slashed-bricks.php`:
- Around line 151-178: Extract the duplicated BRICKS_VERSION/theme metadata
resolution into a new helper slashed_bricks_get_bricks_version() that returns
the Bricks version string or '' and replace the inline resolution in both
slashed_bricks_supports_color_manager() and slashed_bricks_is_bricks_active()
with calls to that helper; ensure the helper implements the same logic currently
used (check defined('BRICKS_VERSION'), then wp_get_theme() and compare
strtolower($theme->get_template()) and strtolower($theme->get('Name')) and
return parent or theme Version as appropriate) so both callers get the same
canonical version string for the existing major/minor comparison.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 98adf7f4-fb58-4e8a-bafb-1d27ef3808f6

📥 Commits

Reviewing files that changed from the base of the PR and between dff8c04 and 1e13fec.

📒 Files selected for processing (3)
  • plugins/SLASHED-for-WP/integrations/bricks/README.md
  • plugins/SLASHED-for-WP/integrations/bricks/includes/class-colors.php
  • plugins/SLASHED-for-WP/integrations/bricks/slashed-bricks.php

Dedupe the BRICKS_VERSION/theme-metadata version resolution shared by slashed_bricks_is_bricks_active() and slashed_bricks_supports_color_manager() so both detectors stay in sync. Behavior unchanged. (CodeRabbit nitpick on #182.)

Co-Authored-By: Jack Granatowski <jack.granatowski@gmail.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Thanks @coderabbitai — applied the nitpick in 8712d88: extracted slashed_bricks_get_bricks_version() and routed both slashed_bricks_is_bricks_active() and slashed_bricks_supports_color_manager() through it, so the BRICKS_VERSION/theme-metadata resolution lives in one place. Behavior is unchanged (php -l clean; the major.minor edge cases still hold).

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
gh api repos/codeslash-dev/SLASHED/commits/8712d88 --jq '.files[] | {filename: .filename, patch: .patch}'

Length of output: 3075



@devin-ai-integration the refactor in 8712d88 looks great. slashed_bricks_get_bricks_version() cleanly consolidates the three-step resolution (constant → template fallback → name fallback → ''), and both slashed_bricks_is_bricks_active() and slashed_bricks_supports_color_manager() now delegate to it with no behavioral change. The version-detection logic is genuinely DRY now — nice clean-up.


If you found this review helpful, would you consider giving us a shout-out on X?

Thank you for using CodeRabbit!

@jackgranatowski
jackgranatowski merged commit c3eab68 into main Jun 1, 2026
9 checks passed
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.

1 participant