juvo/wp-block-bridge

Bridge WordPress blocks to page builders like Bricks and Elementor. Use blocks as the source of truth for styling, scripting, and render logic.

Installs: 18

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 0

Forks: 0

Open Issues: 0

pkg:composer/juvo/wp-block-bridge

1.0.2 2026-01-12 16:23 UTC

This package is auto-updated.

Last update: 2026-01-12 16:23:32 UTC


README

Use WordPress blocks as the source of truth for page builders like Bricks and Elementor.

Features

  • Render block templates in page builder elements
  • Automatic asset enqueueing (script modules)
  • Interactivity API directive processing
  • Unified API for context and attributes across all render contexts

Requirements

  • PHP 8.1+
  • Blocks must be registered using block.json metadata
  • Blocks must be registered globally (e.g., via register_block_type() or wp_register_block_types_from_metadata_collection())

Installation

composer require juvo/wp-block-bridge

Usage

In render.php (Gutenberg + Page Builders)

use juvo\WP_Block_Bridge\Block_Bridge;

// Get context and attributes - works everywhere
$context    = Block_Bridge::context( $block ?? null );
$attributes = Block_Bridge::attributes( $block ?? null );

// Your block markup...
ob_start();
?>
<div class="my-block">
    <!-- block content -->
</div>
<?php

// Wrap and process directives automatically
echo Block_Bridge::render( (string) ob_get_clean(), $block ?? null );

In Bricks Element

use juvo\WP_Block_Bridge\Block_Bridge;

class My_Bricks_Element extends \Bricks\Element {
    public function render(): void {
        Block_Bridge::render_block(
            'my-plugin/my-block',
            __DIR__ . '/render.php',
            [ 'postId' => get_the_ID() ]
        );
    }
}

In Elementor Widget

use juvo\WP_Block_Bridge\Block_Bridge;

class My_Elementor_Widget extends \Elementor\Widget_Base {
    protected function render(): void {
        Block_Bridge::render_block(
            'my-plugin/my-block',
            __DIR__ . '/render.php',
            [ 'postId' => get_the_ID() ]
        );
    }
}

API

Method Description
context($block) Get block context array
attributes($block) Get block attributes array
render($html, $block) Wrap HTML and process directives
render_block($name, $path, $context, $attrs) Full render for page builders
is_bridge_context() Check if rendering via page builder
is_editor_context() Check if in block editor SSR