juvo/wp-block-bridge 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

juvo/wp-block-bridge

最新稳定版本:1.0.0

Composer 安装命令:

composer require 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.

README 文档

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

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-01-09