WordPress Plugin

Define Blocks

Create native Gutenberg blocks entirely in PHP. No React, no JSX, no build step. 30+ field types out of the box.

View on GitHub
$ composer require salvatorecorsi/define-blocks
01

Define a block in PHP

Describe your fields as arrays. Define Blocks generates the full editor UI — content area, sidebar panels, toolbar controls.

Schema
define_block_type( 'theme/hero', [
    'title'  => 'Hero',
    'icon'   => 'cover-image',
    'schema' => [
        [
            'scope'  => 'content',
            'fields' => [
                'heading' => [ 'type' => 'text' ],
                'text'    => [ 'type' => 'richtext' ],
                'image'   => [ 'type' => 'media' ],
            ]
        ],
        [
            'scope'  => 'inspector',
            'panel'  => 'Layout',
            'fields' => [
                'layout' => [
                    'type'    => 'select',
                    'options' => [ 'default', 'wide', 'split' ],
                ],
                'overlay' => [
                    'type' => 'range',
                    'min'  => 0,
                    'max'  => 100,
                ],
            ]
        ],
    ],
    'render' => 'theme_hero_render',
]);
Render
function theme_hero_render( $attributes ) {
    $v   = $attributes['values'];
    $img = wp_get_attachment_image_url(
        $v['image'], 'full'
    );

    ob_start();
    ?>

    <section class="hero">
        <img src="<?= esc_url($img) ?>">
        <div class="hero__content">
            <h1><?= esc_html($v['heading']) ?></h1>
            <?= $v['text'] ?>
        </div>
    </section>

    <?php
    return ob_get_clean();
}
02

Built for developers

Everything you need to build production blocks, nothing you don't.

PHP-first

Define blocks with arrays, render with callbacks. No React, no JSX, no webpack. Your WordPress workflow, unchanged.

Five editor scopes

Place fields in the content area, sidebar panels, advanced section, toolbar, or toolbar dropdowns. Your blocks feel native.

Conditional visibility

Show and hide fields dynamically with a rich expression syntax. Equality, comparison, boolean logic, array inclusion, substring matching.

Nested structures

Repeaters with drag-and-drop reorder. Groups for nested objects. Tabpanels for organized editing. InnerBlocks for composability.

Frontend preview

See the server-side render live in the editor, scoped CSS included. Toggle between editing fields and previewing output.

Extensible

Register custom field types from external plugins. Filter blocks, schema, and rendering with standard WordPress hooks.

03

30+ field types

From simple text inputs to maps and media crop. Ready to use, zero configuration.

Text

text textarea richtext number target

Selection

select multi-select autocomplete multi-autocomplete chips checkbox radio range

Media

media gallery file video

Structure

repeater group tabpanels innerblocks

Data

taxonomy post-selector color date time datetime

Maps

google-map osm-map

Toolbar

toolbar-select toolbar-toggle toolbar-dropdown

Special

html hidden
04

Conditional visibility

Fields appear and disappear based on other field values. One string expression, no callbacks.

'show' => 'has_overlay' Truthy check
'show' => '!has_overlay' Negation
'show' => 'layout == "split"' Equality
'show' => 'count > 3' Numeric comparison
'show' => 'has_cta && layout != "minimal"' Boolean logic
'show' => 'country in ["IT", "FR", "DE"]' Array inclusion
'show' => 'slug contains "hero"' Substring
'show' => '$index > 0' Repeater-aware