承接 offset/blocks 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

offset/blocks

Composer 安装命令:

composer require offset/blocks

包简介

Create Gutenberg blocks more easily

README 文档

README

Installation

composer require offset/blocks

Use

use Offset\Block;

// Create an empty block
$block = new Block();

// Pass the "block.json" file of your Gutenberg block
$block->setSettingsFromJSONPath(__DIR__ . '/block.json');

// Add the file that will be used for the dynamic rendering of your block. You have access to `$attributes` and `$content`.
$block->setRender(__DIR__ . '/template/view.php');

// Save your block in Gutenberg and load the styles and scripts
$block->init();

You can also render the content with a function

// Add the file that will be used for the dynamic rendering of your block. You have access to `$attributes` and `$content`.
$block->setRender(function($attributes, $content) {
    return '<div>My block</div>';
});

Filters and overrides

Filters are automatically added to your blocks to give you greater flexibility in development and customization.

offset_block_attributes

Filter all attributes of all Gutenberg blocks.

Parameters
  • $attributes - array - Block attributes. Default empty array
Example
function attributes_filter($attributes) {
    $attributes['myValue'] = 'Changed';
    return $attributes;
}

add_filter('offset_block_attributes', 'attributes_filter', 10, 1);

offset_block_attributes_{block_name}

Filter the attributes of Gutenberg blocks that have the same name.

The block_name corresponds to the name parameter in the block.json file, replacing special characters with _ (example: offset-pack/block-one -> offset_pack_block_one).

Parameters
  • $attributes - array - Block attributes. Default empty array
Example
function attributes_filter($attributes) {
    $attributes['myValue'] = 'Changed';
    return $attributes;
}

add_filter('offset_block_attributes_offset_pack_block_one', 'attributes_filter', 10, 1);

offset_block_content

Filters all contents of all Gutenberg blocks.

Parameters
  • $content - string - Block content. Default empty string.
Example
function content_filter($content) {
    $content .= 'Add new line';
    return $content;
}

add_filter('offset_block_content', 'content_filter', 10, 1);

offset_block_content_{block_name}

Filter the content of Gutenberg blocks that have the same name.

The block_name corresponds to the name parameter in the block.json file, replacing special characters with _ (example: offset-pack/block-one -> offset_pack_block_one).

Parameters
  • $content - string - Block content. Default empty string.
Example
function content_filter($content) {
    $content .= 'Add new line';
    return $content;
}

add_filter('offset_block_content_offset_pack_block_one', 'content_filter', 10, 1);

offset_block_render_{block_name}

Filter the html of Gutenberg blocks that have the same name.

The block_name corresponds to the name parameter in the block.json file, replacing special characters with _ (example: offset-pack/block-one -> offset_pack_block_one).

Parameters
  • $html - string - Block html. Default empty string
  • $attributes - array - Block attributes. Default empty array
  • $content - string - Block content. Default empty string.
Example
function render_filter($html, $attributes, $content) {
    $html .= '<div>Add new block</div>';
    return $html;
}

add_filter('offset_block_render_offset_pack_block_one', 'render_filter', 10, 3);

offset_block_is_style_enqueue

Remove styles from all Gutenberg blocks.

Example

add_filter('offset_block_is_style_enqueue', '__return_false');

offset_block_is_style_enqueue_{block_name}

Remove styles from Gutenberg blocks with the same name.

The block_name corresponds to the name parameter in the block.json file, replacing special characters with _ (example: offset-pack/block-one -> offset_pack_block_one).

Example

add_filter('offset_block_is_style_enqueue_offset_pack_block_one', '__return_false');

offset_block_is_script_enqueue

Remove scripts from all Gutenberg blocks.

Example

add_filter('offset_block_is_script_enqueue', '__return_false');

offset_block_is_script_enqueue_{block_name}

Remove scripts from Gutenberg blocks with the same name.

The block_name corresponds to the name parameter in the block.json file, replacing special characters with _ (example: offset-pack/block-one -> offset_pack_block_one).

Example

add_filter('offset_block_is_script_enqueue_offset_pack_block_one', '__return_false');

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-12-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固