Global Classes
The Jalpi Page Builder Class-Based Styling System provides reusable, site-wide CSS classes that can be attached to unlimited elements across every page. Modifying a Global Class instantly updates every element linked to it, establishing unified design consistency, minimizing stylesheet bloat, and eliminating repetitive inline styling.
Global Classes Overview#
Traditional WordPress page builders store styles directly inside each element's JSON data (inline/element-level styling). While convenient for quick edits, styling ten cards or twenty CTA buttons independently requires twenty repetitive style operations. When brand specifications change, every element must be manually hunted down and re-edited.
Jalpi solves this with Global Classes. Stored in a dedicated database table ({prefix}jalpi_classes), Global Classes act as centralized styling templates. Elements reference classes by an immutable internal key (e.g. cls_9f3a1b2c), and Jalpi's server-side compiler dynamically generates clean, shared CSS classes (e.g. .card-shadow) rendered only when in use.
Core Benefits
Single Source of Truth
Define design properties once. If a card's border radius or shadow changes, editing the class updates all elements across the entire website instantly.
Zero CSS Bloat
Instead of generating 50 duplicate CSS rules for 50 identical widgets, Jalpi outputs a single shared CSS rule (.card-elevated) and enqueues it once.
Strict Brand Consistency
Prevent style fragmentation across teams. Team members can simply assign approved classes (e.g. .btn-primary, .feature-box) without guessing margins or colors.
Instant Cache Invalidation
Editing a class bumps an atomic version token (jalpi_classes_version), invalidating frontend page transients across the entire site with zero database resaves.
Architecture & Headless Node Pattern
In Jalpi's internal architecture, a Global Class is structured as a headless node. It possesses the exact same styling containers as a real canvas widget: styles (desktop), tabletStyles, mobileStyles, and a settings bucket containing background (bgNormal, bgHover) and border (borderNormal, borderHover) definitions.
Because the data structures are identical, Jalpi_Renderer compiles Global Classes using the same battle-tested engine helpers (styles_to_css, bg_data_to_css, border_data_to_css) used for elements, ensuring 100% visual fidelity between the editor and frontend output.
Creating a Global Class#
Jalpi provides two streamlined workflows for creating Global Classes: Inline Creation while designing on canvas, and Centralized Creation inside the dedicated Classes Panel.
1. Inline Creation via Properties Panel
The fastest way to convert an element's styles or start a new reusable class is directly from the element inspector:
- Select an Element: Click any widget, container, or column on the canvas.
- Open Advanced Controls: In the right-hand inspector panel, ensure the Style (Properties) tab is selected and scroll down to the CSS accordion group.
- Focus the Classes Field: Under Classes, you will find the
ClassPickerchip input showing "Search or create a classβ¦" (or "Add classβ¦" if other classes are already attached). - Enter Desired Name: Type the desired CSS class name (e.g.
card-shadoworbadge-pill). Jalpi automatically sanitizes the input viasanitize_html_class(). - Create & Attach: If no existing class matches, click the dropdown item + Create ".card-shadow" or press Enter.
- Automatic Attachment: Jalpi calls
POST /wp-json/jalpi-page-builder/v1/classes, returns the server-generated record, and automatically attaches the new class chip to your element. - Open Style Editor: Click directly on the newly created chip
.card-shadowto open the Class Style Editor Modal and configure its typography, background, borders, and margins.
.). The editor displays the dot for clarity, but stores clean CSS identifier tokens.2. Site-Wide Creation via Classes Panel
When planning a design system upfront before building canvas sections:
- Open the Classes Tab: In the main inspector tab bar (next to Outline, Style, Page, and Global), click the Classes tab (icon with two brackets / classes symbol).
- Enter Class Name: In the toolbar row, locate the text input with placeholder "New class nameβ¦".
- Click New Class: Enter the name and click the teal + New Class button (or press Enter).
- Immediate Availability: The class appears in the site-wide class list and immediately opens in the Style Editor modal, ready to be configured.
Applying a Global Class#
Once a Global Class exists, it can be applied to any number of elements across any page on the WordPress site.
Attaching Classes to Elements
- Select the target element on the canvas.
- Navigate to Advanced β CSS β Classes in the Properties Panel.
- Click into the text input. A dropdown list displays available site classes.
- Type any substring to filter classes in real time (e.g. typing "btn" displays
.btn-primary,.btn-outline,.btn-ghost). - Click any suggestion or press Enter when highlighted. The class attaches as an interactive chip.
Inherited Style Indicator (from .class)
When an element inherits styles from an attached Global Class, Jalpi prevents confusion by displaying an Inherited Badge in the element's style controls:
[Margin] from .card-shadow
ββββββββββ¬βββββββββ¬βββββββββ¬βββββββββ
β Top β Right β Bottom β Left β
β 16px β 16px β 16px β 16px β <-- Inherited value displayed in muted state
ββββββββββ΄βββββββββ΄βββββββββ΄βββββββββThe badge displays from .{class-name}. Hovering over it shows the tooltip: "Inherited from .{class-name} β set a value here to override it locally." If you enter a local value into that control, the local value takes precedence and the badge disappears.
Detaching Classes from Elements
To detach a class from a specific element:
- Click the small remove icon (Γ) on the right side of the class chip.
- The class key is immediately removed from the element's
settings.cssClassesarray. - The element instantly reverts to its local element styles and default widget styling.
- Crucial: Detaching an element chip never deletes the class from other elements or from the site database.
Class Management#
The Classes Panel (accessible via the Classes tab in the right-hand inspector) serves as the central mission control for your entire site-wide class library.
The Classes Panel Workspace
The panel includes a comprehensive suite of management tools:
- Search Bar: Filter classes by name in real time using case-insensitive substring matching.
- Favorite Filter: Click the star icon (
β) in the toolbar to isolate only starred/favorite classes. - Usage Counters: Each row displays an instant badge showing how many times the class is used on the current page (e.g.
4Γ). - Editing Indicator: Classes currently open in the style editor are highlighted with an active border and background.
Renaming, Favoriting & Reordering
| Action | UI Trigger | Internal Behavior |
|---|---|---|
| Edit Styles | Single-click on class name (.{name}) | Sets editingClassKey in store and opens ClassStyleEditorModal with live preview. |
| Rename Class | Double-click on class name (.{name}) | Opens an inline text input. Press Enter or blur to commit. Jalpi updates the name, auto-uniquifies collisions, and triggers PATCH /classes/{key}. |
| Toggle Favorite | Click star icon (β
) on class row | Toggles boolean favorite flag via POST /classes/{key}/favorite. Favorites pin frequently used utility classes for quick filtering. |
| Reorder (Up/Down) | Click Chevron Up (β²) or Down (βΌ) | Swaps position in the class list and persists order via POST /classes/reorder. Important: List order directly controls multi-class CSS cascade precedence! |
Duplication & Protected Deletion
Duplication: Clicking the duplicate icon (two overlapping rectangles) clones the class, its 4 style buckets, and any design-system token references under the name {original}-copy (e.g. card-shadow-copy). Collisions automatically become -copy-2, -copy-3.
Protected Deletion: Deleting a class that is actively used across a website can disrupt layouts. Jalpi protects against accidental breakage with an asynchronous usage verification workflow:
- Click the trash icon on any class row.
- Jalpi opens a confirmation modal and immediately queries
GET /wp-json/jalpi-page-builder/v1/classes/{key}/usage. - The endpoint executes a SQL scan of the
wp_jalpi_pagestable to count exact page references site-wide. - If references exist, the modal warns: "This class is referenced on {count} page(s) site-wide. Deleting it removes its styling from every widget it's attached to."
- Confirming deletion calls
DELETE /classes/{key}. Node references on existing pages simply ignore the missing class during render without crashing or displaying errors.
Export & Import Workflows
In the footer of the Classes Panel, two dedicated buttons enable cross-site class sharing:
- Export: Clicking Export calls
GET /classes/exportand downloadsjalpi-classes.jsoncontaining all class definitions, sort orders, and style maps stamped with the plugin version. - Import: Clicking Import opens a native file selector. Uploading a JSON export payload calls
POST /classes/import. The server supports three conflict strategies:skip(Default): Leaves existing classes with matching keys unchanged.overwrite: Updates existing class styles in-place with the incoming definitions.duplicate: Re-creates the incoming classes under fresh keys with-copysuffixes.
Global Class Styling#
Clicking any class name in the Classes Panel or chip in the Properties Panel opens the Class Style Editor Modal (ClassStyleEditorModal). Changes made here apply across every element attached to that class.
Class Style Editor Modal Interface
The modal features a clean modal header displaying the class name (e.g. .card-elevated), a live usage notice ("Used on X elements on this page β changes apply everywhere this class is attached"), and collapsible accordion groups for all supported styling domains.
Every slider, color picker, or spacing input triggers store.upsertClass() instantly, rendering updates on the canvas in real time. A debounced 500ms timer handles persisting updates to the REST API in the background.
Supported Styling Properties
| Domain | Supported Properties | Hover State Support |
|---|---|---|
| Typography |
| Supported (Normal / Hover tabs for Color) |
| Background |
| Supported (bgNormal vs bgHover buckets) |
| Border |
| Supported (borderNormal vs borderHover buckets) |
| Spacing |
| Normal State |
Multiple Classes#
Jalpi fully supports attaching multiple Global Classes to a single element, enabling utility-first or component-oriented design patterns (e.g. combining .card with .theme-dark and .shadow-lg).
Multi-Class Combination
When an element has multiple classes attached in settings.cssClasses, Jalpi resolves their names and outputs them in the HTML class attribute alongside any custom element classes:
<div class="jalpi-node-w8f2a card-base shadow-elevated border-accent custom-user-class">
<!-- Widget Content -->
</div>Cascade Precedence & Tie Breaking
When two attached classes define the same CSS property (for example, .card-base sets background-color: #ffffff while .theme-dark sets background-color: #1e293b), how does Jalpi determine which class wins?
- Database Sort Order Drives CSS Output: In
Jalpi_Renderer::compile_class_css(), all used classes are sorted bysortOrderascending before stylesheet rules are printed:includes/class-jalpi-renderer.phpPHPusort( $classes, static fn( $a, $b ) => $a['sortOrder'] <=> $b['sortOrder'] ); - CSS Source Order Rule: In standard CSS, when two class selectors have identical specificity (e.g.
.card-basevs.theme-dark, specificity0-1-0), the rule defined later in the stylesheet wins. - Visual Reordering: In the Classes Panel, clicking Move Down increases a class's
sortOrder, placing its CSS rules further down the generated stylesheet. Therefore, classes positioned lower in the manager list have higher cascade priority and override earlier classes. - Editor Inheritance Order: The inspector's
inheritedFrom()helper mirrors this exact rule: it scans attached classes in reverse order (for (let i = attachedClasses.length - 1; i >= 0; i--)) to ensure the editor UI always highlights the exact winning class.
Responsive Classes#
Global Classes in Jalpi are natively responsive. A single class can define base styling for Desktop, along with targeted overrides for Tablet and Mobile viewports.
Desktop, Tablet & Mobile Breakpoints
The class data structure maintains three independent style buckets:
styles: Desktop baseline styles (applies to all screen widths unless overridden).tabletStyles: Overrides applied at the Tablet breakpoint (default:max-width: 1024px).mobileStyles: Overrides applied at the Mobile breakpoint (default:max-width: 767px).
When editing in the visual editor, toggling the top-bar breakpoint switcher (Desktop / Tablet / Mobile) switches the target bucket automatically. Values left blank at a narrower breakpoint automatically inherit from the wider breakpoint.
Media Query Output & Fallbacks
When rendering frontend pages, Jalpi_Renderer compiles these buckets into organized responsive media query blocks:
/* 1. Desktop Global Class Rules */
.card-shadow { box-shadow: 0 4px 16px rgba(0,0,0,0.12); padding: 32px; }
.card-shadow:hover { box-shadow: 0 8px 24px rgba(0,0,0,0.18); }
/* 2. Tablet Media Query (max-width: 1024px) */
@media (max-width: 1024px) {
.card-shadow { padding: 24px; }
}
/* 3. Mobile Media Query (max-width: 767px) */
@media (max-width: 767px) {
.card-shadow { padding: 16px; border-radius: 8px; }
}Breakpoint widths are read dynamically from Jalpi_Settings::get('breakpoints'), ensuring that custom site breakpoints configured under Editor Settings are respected across all Global Classes.
Class Naming#
Jalpi enforces strict server-side validation and sanitization to ensure that class names always generate valid, crash-free CSS selectors.
Sanitization & Validation Rules
| Criterion | Enforcement Rule | Behavior / Example |
|---|---|---|
| Allowed Characters | [a-zA-Z0-9_-] | Passed through WordPress core sanitize_html_class(). Uppercase letters are preserved. |
| Spaces & Punctuation | Stripped or converted | Entering "card shadow & highlight" is sanitized to valid identifier tokens. Spaces are removed or hyphenated. |
| Leading Dots | Automatically removed | Entering .my-class strips the leading dot; the class is saved cleanly as my-class. |
| Empty / Invalid Fallback | Fallback to 'class' | If input sanitizes to an empty string (e.g. only symbols entered), the server falls back to literal class. |
Auto-Uniquification & Server Keys
Class names are guaranteed unique site-wide. When a class name collision occurs:
Jalpi_Class_Manager::unique_name()checks existing classes.- If
card-shadowalready exists, saving another class with the same name automatically becomescard-shadow-2. Subsequent collisions becomecard-shadow-3,card-shadow-4, etc. - Internal Server Key: The client never invents the database identifier. The server generates an immutable key matching
cls_followed by 8 random hex characters (e.g.cls_9f3a1b2c) usingbin2hex(random_bytes(4)). Even if a class is later renamed from.hero-cardto.featured-card, its immutable key ensures existing element references remain intact.
Global Classes vs Element Styles#
Understanding when to use a Global Class versus an Element Style is fundamental to building scalable, high-performance Jalpi websites.
Architectural Comparison
| Dimension | Global Classes | Element Styles (Inline) |
|---|---|---|
| Scope | Site-wide across unlimited pages and elements | Scoped strictly to a single widget node |
| Storage Location | Central database table: {prefix}jalpi_classes | Embedded inside page JSON in wp_jalpi_pages |
| CSS Specificity & Precedence | Class selector (.card-base, specificity 0-1-0). Emitted first in stylesheet. | Node ID selector (.jalpi-node-w8f2a). Emitted after class rules, overriding class declarations. |
| Updating & Maintenance | Single edit updates all linked elements site-wide automatically | Requires editing each element individually |
| Cache Invalidation | Increments jalpi_classes_version, invalidating render transients site-wide | Invalidates only the specific post's render transient |
| CSS Payload Size | Generates 1 CSS rule regardless of how many widgets use it | Generates unique CSS declarations for every widget instance |
When to Use Each Approach
- Use Global Classes for:
- UI components repeated across pages: Cards, Testimonial cards, Service boxes, Pricing tables.
- Button variations:
.btn-primary,.btn-secondary,.btn-pill. - Typography patterns: Special pull quotes, section subtitles, badge labels.
- Standardized padding/margin containers used throughout your design system.
- Use Element Styles for:
- One-off layout adjustments unique to a specific page or section.
- Specific element positioning (e.g. absolute coordinates for a decorative graphic).
- Overriding a single property of a global class (e.g. setting a unique custom background color on one specific card while keeping the global class's padding and borders).
Updating a Global Class#
When a Global Class is modified, Jalpi utilizes a dual-tier update pipeline to ensure both instantaneous editor feedback and immediate site-wide cache synchronization.
Live In-Editor Propagation
If a page contains 15 cards with the .service-card class attached:
- Open the style editor modal for
.service-card. - Adjust the border radius from
8pxto24pxor change the hover box-shadow. - Immediate Reactivity: The editor store executes
store.upsertClass()in memory. All 15 cards on the active canvas update instantly and simultaneously without requiring a canvas reload or page save. - Debounced Persistence: 500 milliseconds after your last adjustment, an asynchronous
PATCH /wp-json/jalpi-page-builder/v1/classes/{key}request persists the new definition to the database.
Site-Wide Render Cache Invalidation
How do changes reach pages that are currently cached in production?
Rather than executing an expensive SQL table scan to rebuild every cached post, Jalpi uses a high-performance atomic version bump pattern:
public function cache_key( int $post_id ): string {
return 'jalpi_render_' . $post_id . '_' . JALPI_VERSION . '_c' . Jalpi_Class_Manager::instance()->version();
}- Every time any class is created, updated, or deleted,
Jalpi_Class_Manager::bump_version()increments the WordPress optionjalpi_classes_version. - Because the version integer is folded directly into every page's render transient key (e.g.
jalpi_render_42_1.0.5_c7), old transients instantly become unreachable. - The next time any visitor requests any page on the site, Jalpi generates fresh HTML and CSS reflecting the updated class definition. Unreachable old transients expire naturally within their normal TTL with zero database maintenance required.
Removing a Global Class#
Detaching vs Deleting Safe Behaviors
| Operation | Scope | What Happens to Elements | Database Impact |
|---|---|---|---|
| Detaching from an Element | Single widget | Element's settings.cssClasses array removes the key. The element immediately loses the class styling and falls back to local element styles. Other elements on the site are completely unaffected. | Saved to post JSON when the page is updated. |
| Deleting the Class from Site | Site-wide | The class record is removed from {prefix}jalpi_classes. All widgets site-wide that reference the deleted key simply skip it at render time (Jalpi_Renderer::get_css_attrs()). No broken HTML, no missing CSS errors. | Row deleted from custom table; jalpi_classes_version bumped; jalpi_class_deleted action fires. |
Developer Reference#
Technical architecture, database structures, actions, and REST API routes verified against the current Jalpi Page Builder codebase.
PHP Architecture & Data Layer
| Class | File Location | Primary Responsibility |
|---|---|---|
Jalpi_Class_Manager | includes/class-jalpi-class-manager.php | Singleton data access layer. Manages table creation, in-request caching, object caching (jalpi_classes_all, 1 hour TTL), CRUD, version bumps, uniquification, export, and import. |
Jalpi_Classes_API | includes/class-jalpi-classes-api.php | Registers all 10 REST API routes under /wp-json/jalpi-page-builder/v1/classes. Enforces edit_posts capability check. |
Jalpi_Renderer | includes/class-jalpi-renderer.php | Compiles class styles via compile_class_css(), resolves classes in get_css_attrs(), and folds version into render transient keys. |
Jalpi_Sanitizer | includes/class-jalpi-sanitizer.php | Validates incoming class payloads via sanitize_class_definition() before database insertion. |
Database Schema ({prefix}jalpi_classes)
CREATE TABLE IF NOT EXISTS {$wpdb->prefix}jalpi_classes (
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
class_key VARCHAR(64) NOT NULL,
name VARCHAR(191) NOT NULL,
styles LONGTEXT NOT NULL,
favorite TINYINT(1) NOT NULL DEFAULT 0,
sort_order INT UNSIGNED NOT NULL DEFAULT 0,
created_by BIGINT UNSIGNED NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (id),
UNIQUE KEY class_key (class_key),
KEY sort_order (sort_order)
) {$charset};Hooks & Action Reference
| Hook Name | Type | Parameters | Description |
|---|---|---|---|
jalpi_class_saved | Action | string $key, array $class | Fires whenever a class is created, updated, duplicated, or has its favorite flag toggled. Deep-linked to Hooks Documentation. |
jalpi_class_deleted | Action | string $key | Fires when a class row is deleted from the database. Deep-linked to Hooks Documentation. |
jalpi_before_compile_class_css | Filter | string $rules_css, array $used_class_keys | Filters compiled desktop class CSS string before it is combined with element rules. |
REST API Endpoints Reference
All ten endpoints operate under namespace jalpi-page-builder/v1, require WordPress cookie authentication + REST nonce (X-WP-Nonce), and verify capability edit_posts. Cross-referenced to REST API Documentation.
| Method | Endpoint | Description |
|---|---|---|
| GET | /classes | Returns array of all class records, ordered by sort_order ASC. Supports search and favorite query parameters. |
| POST | /classes | Creates a new class. Accepts name, styles, tabletStyles, mobileStyles, settings, globalStyleRef, favorite. |
| PATCH | /classes/{key} | Partial update of class properties. Explicit null on globalStyleRef clears design token link. |
| DELETE | /classes/{key} | Deletes class record. Returns { deleted: bool } with 200 OK. |
| POST | /classes/{key}/duplicate | Duplicates target class under {name}-copy. |
| POST | /classes/{key}/favorite | Inverts the boolean favorite status flag. |
| GET | /classes/{key}/usage | Performs on-demand SQL LIKE scan of wp_jalpi_pages to return { count: int }. |
| POST | /classes/reorder | Persists updated sort orders (1, 2, 3...) from an array of keys. Drives CSS cascade precedence. |
| GET | /classes/export | Returns { version, classes[] } for cross-site portability. |
| POST | /classes/import | Imports array of classes with conflict resolution (skip, overwrite, duplicate). |
Roadmap & Coming Soon Features
The following advanced class capabilities are planned for upcoming Jalpi Page Builder updates and are currently badged as Coming Soon:
Advanced Pseudo-Classes
π SoonStyling :focus, :active, :focus-visible, and :visited states directly within class definitions.
Class Folders & Tagging
π SoonOrganize extensive class collections into custom folders (Layout, Typography, Buttons, Effects).
Scoped Custom CSS
π SoonWrite raw CSS blocks directly inside a class definition with automatic selector scoping.
Last updated: November 2026