PHP code example of offset / blocks

1. Go to this page and download the library: Download offset/blocks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

offset / blocks example snippets


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();

// 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>';
});

function attributes_filter($attributes) {
    $attributes['myValue'] = 'Changed';
    return $attributes;
}

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

function attributes_filter($attributes) {
    $attributes['myValue'] = 'Changed';
    return $attributes;
}

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

function content_filter($content) {
    $content .= 'Add new line';
    return $content;
}

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

function content_filter($content) {
    $content .= 'Add new line';
    return $content;
}

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

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);

add_filter('offset_block_is_style_enqueue', '__return_false');

add_filter('offset_block_is_style_enqueue_offset_pack_block_one', '__return_false');

add_filter('offset_block_is_script_enqueue', '__return_false');

add_filter('offset_block_is_script_enqueue_offset_pack_block_one', '__return_false');