Skip to content

Architecture ​

How Styble Pro is put together: a dual JavaScript + PHP block system with auto-registration, dynamic rendering, and server-side CSS generation.

Styble Pro is a WordPress Gutenberg blocks plugin built on a hybrid architecture. Every block is defined twice β€” once in JavaScript (for the editor experience) and once in PHP (for registration and, when needed, server-side rendering). This page gives you the mental model and points you to the deeper developer guides.

Two sides of every block ​

SideLives inResponsibility
JavaScriptsrc/blocks/<block-name>/Editor UI (edit.jsx), save markup (save.jsx), block registration (index.js), inspector controls, and dynamic editor CSS.
PHPblocks/Types/<Block_Name>/Server-side registration, attribute definitions (attributes.php), and render_block() for dynamic blocks.

Static blocks save their own markup in save.jsx and need no PHP rendering. Dynamic blocks return null from save.jsx and produce their HTML in PHP via render_block().

Directory map ​

text
styble-pro/
β”œβ”€β”€ styble-pro.php                 # Main plugin file, defines constants, boots Block_Init
β”œβ”€β”€ composer.json                  # PSR-4 autoload: ShapedPlugin\StyblePro\ β†’ blocks/
β”œβ”€β”€ webpack.config.js              # Build config + JS path aliases
β”œβ”€β”€ gulpfile.js                    # Standalone SCSS compilation
β”‚
β”œβ”€β”€ src/                           # JavaScript source (built with @wordpress/scripts)
β”‚   β”œβ”€β”€ blocks/                    # One folder per block (index.js, edit.jsx, save.jsx, …)
β”‚   β”‚   └── index.js               # Imports + registers every block for the editor
β”‚   β”œβ”€β”€ admin/                     # React admin dashboard
β”‚   β”œβ”€β”€ components/                # Shared React components
β”‚   β”œβ”€β”€ controls/                  # Inspector controls + constants
β”‚   β”œβ”€β”€ hooks/                     # Reusable hooks (e.g. useApiData)
β”‚   β”œβ”€β”€ global-settings/           # Global settings store + sidebar
β”‚   └── icons/                     # Block + category icons
β”‚
└── blocks/                        # PHP root β€” PSR-4 base (ShapedPlugin\StyblePro\)
    β”œβ”€β”€ Block_Init.php             # Core bootstrap class
    β”œβ”€β”€ Types/                     # One folder per PHP block (class + attributes.php)
    β”œβ”€β”€ Includes/                  # Core engine
    β”‚   β”œβ”€β”€ AbstractBlock.php      # Base class for every PHP block
    β”‚   β”œβ”€β”€ Blocks_Register.php    # Auto-registers blocks by scanning Types/
    β”‚   β”œβ”€β”€ Blocks_Query.php       # AJAX query endpoints
    β”‚   β”œβ”€β”€ PostQueryHandler.php   # WP_Query construction
    β”‚   β”œβ”€β”€ AssetManager.php       # Script/style registration & enqueueing
    β”‚   β”œβ”€β”€ Styles/                # Per-block dynamic CSS classes
    β”‚   └── Utils/                 # DynamicCssGenerator, Css_Helpers, Transient_Registry…
    β”œβ”€β”€ Attributes/
    β”‚   └── CommonAttributes.php   # Attributes shared by all blocks
    β”œβ”€β”€ assets/                    # Compiled frontend JS/CSS for blocks
    └── languages/                 # Translation files (.pot/.po/.mo)

PSR-4 autoloading

The blocks/ directory is the root of the ShapedPlugin\StyblePro\ namespace (see composer.json). A class such as ShapedPlugin\StyblePro\Includes\AbstractBlock maps to blocks/Includes/AbstractBlock.php. The constant SP_STYBLE_PATH (defined in styble-pro.php) also points to blocks/.

Registration flow ​

Everything starts in styble-pro.php, which defines plugin constants and instantiates Block_Init.

text
styble-pro.php
   └─ Block_Init::instance()              blocks/Block_Init.php
        └─ init_styble_blocks()
             β”œβ”€ Blocks_Register::instance()    blocks/Includes/Blocks_Register.php
             β”‚     └─ scans blocks/Types/ β†’ instantiates each block class
             β”‚            └─ new <Block> extends AbstractBlock
             β”‚                   β”œβ”€ set_block_properties()   (block sets its slug etc.)
             β”‚                   β”œβ”€ load_attributes()        (merges Common + per-block)
             β”‚                   └─ register_block()         β†’ register_block_type()
             β”œβ”€ Blocks_Query::instance()       (AJAX endpoints)
             β”œβ”€ Block_Dynamic_Style::instance()(dynamic CSS engine)
             └─ AssetManager::instance()       (editor/frontend/dashboard assets)

The key moving parts:

  1. Block_Init (blocks/Block_Init.php) wires up registration, queries, dynamic styles, assets, the text domain, and cache clearing on save_post / deleted_post.
  2. Blocks_Register (blocks/Includes/Blocks_Register.php) scans the blocks/Types/ directory, converts each folder name to StudlyCase, and instantiates the matching class \ShapedPlugin\StyblePro\Types\<Name>\<Name>.
  3. AbstractBlock (blocks/Includes/AbstractBlock.php) is the base class. Its constructor calls set_block_properties(), load_attributes(), and register_block() in sequence, ending with a call to WordPress' register_block_type().

On the JavaScript side, src/blocks/index.js imports each block folder, which in turn calls a small wrapper (registerStybleBlock) around registerBlockType() to register the block in the editor.

Where to go next ​

GuideWhat it covers
Creating a Custom BlockBuilding a block end to end β€” JS files and the PHP class.
Attributes SystemCommonAttributes, per-block attributes.php, and the merge flow.
Dynamic CSS GenerationDynamicCssGenerator, Css_Helpers, per-block style classes, and caching.
Query & AJAXBlocks_Query, PostQueryHandler, transient caching, and the useApiData hook.
Hooks & InternationalizationFilters, actions, and the styble-pro text domain.
Build & Assetsnpm/gulp/webpack workflow and AssetManager.

For the end-user perspective on individual blocks, see the User Docs.

Released under the GPL-2.0-or-later License.