Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions integrations/bricks/includes/class-classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@
* Strategy
* --------
* Bricks reads global classes from the wp_options row `bricks_global_classes`
* (and class categories from `bricks_global_classes_categories`). We treat
* SLASHED entries as managed/virtual - the same pattern the Colors module
* uses for the color palette option:
* (categories from `bricks_global_classes_categories`). Both options are read
* via get_option() inside Bricks' Database::__construct() which runs during
* theme functions.php load — before after_setup_theme fires. This class must
* therefore be instantiated at plugins_loaded (handled in slashed-bricks.php)
* so our option filters are registered before that first read.
*
* We treat SLASHED entries as managed/virtual:
*
* 1. On every read of either option, inject our entries.
* 2. On every write (save from the UI, import, etc.), strip our entries
Expand Down
43 changes: 22 additions & 21 deletions integrations/bricks/includes/class-colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,26 @@
/**
* Class Slashed_Bricks_Colors
*
* Registers SLASHED color tokens with Bricks Builder as a set of separate,
* named color palettes that appear under the "Color palettes" dropdown of
* the Bricks color picker - distinct from the site's global colors.
* Registers SLASHED color tokens with Bricks Builder as a set of named color
* palettes that appear under the Color Manager palette dropdown.
*
* Strategy
* --------
* Bricks stores user-managed color palettes in the wp_options row
* `bricks_color_palette`. We treat SLASHED palettes as managed/virtual:
* Bricks stores color palettes in the wp_options row `bricks_color_palette`
* as an array of `{id, name, colors:[{id,name,hex}]}` palette-group objects.
* We treat SLASHED palettes as managed/virtual:
*
* 1. On every read of that option (option_bricks_color_palette /
* default_option_bricks_color_palette), we inject our palettes into
* the array Bricks sees.
* 2. On every write (pre_update_option_bricks_color_palette), we strip
* our palettes back out so the database never persists them. That
* way the integration is the single source of truth - bumping the
* framework or changing the active bundle automatically updates
* what Bricks shows, without leaving stale rows behind on the site.
* 1. On every read of the option (option_bricks_color_palette /
* default_option_bricks_color_palette) we inject our palette groups.
* The plugin is registered early (plugins_loaded) so our filters are
* in place before Bricks' Database::__construct() reads the option.
* 2. On every write (pre_update_option_bricks_color_palette) we strip
* our palettes back out so the DB never persists them. The plugin
* remains the single source of truth.
*
* Each palette's swatch references the framework variable directly via
* var(--sf-color-X). Modern browsers resolve var() inside the picker
* preview because the SLASHED bundle is loaded into the editor iframe.
* This keeps swatches in sync with theme customization and dark mode.
* Each color swatch references the framework variable via var(--sf-color-X).
* The SLASHED bundle loaded in the editor iframe resolves the var() reference
* so swatches track the live theme including dark mode and token overrides.
*
* Note: the 'raw' field is included alongside 'hex' for forward
* compatibility with Bricks 1.9.2+, which prefers 'raw' when present.
Expand Down Expand Up @@ -64,14 +62,17 @@ class Slashed_Bricks_Colors {
* Constructor. Register hooks.
*/
public function __construct() {
// Inject SLASHED palettes when Bricks (or anything else) reads the
// bricks_color_palette option. Run late so any other plugin's
// additions are preserved.
// Inject SLASHED named palette groups when Bricks reads the palette
// option. This populates the Color Manager dropdown with organized,
// labeled palettes (Primary, Secondary, …) rather than anonymous
// swatches. The bricks/builder/color_palette filter is intentionally
// not used here: per the Bricks forum that filter cannot assign names
// — "id and name are generated after it is applied" — making it
// unsuitable for Color Manager integration.
add_filter( 'option_bricks_color_palette', array( $this, 'inject_palettes' ), 20 );
add_filter( 'default_option_bricks_color_palette', array( $this, 'inject_palettes' ), 20 );

// Strip SLASHED palettes before they are persisted back to the DB.
// pre_update_option_* signature is ($value, $old_value, $option).
add_filter( 'pre_update_option_bricks_color_palette', array( $this, 'strip_palettes' ), 10, 1 );
}

Expand Down
15 changes: 10 additions & 5 deletions integrations/bricks/includes/class-variables.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
* Strategy
* --------
* Bricks 1.9.8+ stores user-managed variables in the `bricks_global_variables`
* wp_option (categories in `bricks_global_variables_categories`). Same as
* the Colors and Classes modules, we treat SLASHED entries as managed/virtual:
* inject on read, strip on save, so the integration is the single source of
* truth and bumping the framework or switching the active CSS bundle keeps
* the Variable Manager in sync without leaving stale rows in the DB.
* wp_option (categories in `bricks_global_variables_categories`). Both options
* are read via get_option() inside Bricks' Database::__construct() which runs
* during theme functions.php load — before after_setup_theme fires. This class
* must therefore be instantiated at plugins_loaded (handled in slashed-bricks.php)
* so our option filters are registered before that first read.
*
* We treat SLASHED entries as managed/virtual: inject on read, strip on save,
* so the integration is the single source of truth and bumping the framework or
* switching the active CSS bundle keeps the Variable Manager in sync without
* leaving stale rows in the DB.
*
* Naming
* ------
Expand Down
41 changes: 33 additions & 8 deletions integrations/bricks/slashed-bricks.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,28 +131,53 @@ function slashed_bricks_admin_init() {
}

/**
* Initialize the plugin.
* Data managers: early initialization at plugins_loaded.
*
* Bricks' Database::__construct() reads bricks_global_variables,
* bricks_global_classes, and bricks_color_palette via get_option() during
* theme functions.php load — which happens AFTER plugins_loaded but BEFORE
* after_setup_theme. Registering our option filters here guarantees they are
* in place when Bricks reads those options for the first time.
*
* Runs unconditionally: if Bricks is not the active theme the option filters
* simply never fire, which is harmless.
*/
function slashed_bricks_init() {
if ( ! slashed_bricks_is_bricks_active() ) {
add_action( 'admin_notices', 'slashed_bricks_missing_bricks_notice' );
function slashed_bricks_data_init() {
// Bail early on non-Bricks sites to avoid loading classes needlessly.
if ( 'bricks' !== strtolower( (string) get_option( 'template', '' ) ) ) {
return;
}

require_once SLASHED_BRICKS_PATH . 'includes/class-token-defaults.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-css-generator.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-css-parser.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-inventory.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-enqueue.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-variables.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-classes.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-colors.php';

new Slashed_Bricks_Enqueue();
new Slashed_Bricks_Variables();
new Slashed_Bricks_Classes();
new Slashed_Bricks_Colors();
}
add_action( 'plugins_loaded', 'slashed_bricks_data_init', 20 );

/**
* CSS enqueue: late initialization at after_setup_theme.
*
* Enqueue needs the theme to be active and Bricks version checks to pass.
* Data managers (variables, classes, colors) are already initialized above.
*/
function slashed_bricks_init() {
if ( ! slashed_bricks_is_bricks_active() ) {
add_action( 'admin_notices', 'slashed_bricks_missing_bricks_notice' );
return;
}

require_once SLASHED_BRICKS_PATH . 'includes/class-token-defaults.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-css-generator.php';
require_once SLASHED_BRICKS_PATH . 'includes/class-enqueue.php';

new Slashed_Bricks_Enqueue();
}
add_action( 'after_setup_theme', 'slashed_bricks_init' );

/**
Expand Down