Turn a GCB block.fields.json controls schema into a WordPress block attribute schema — the PHP companion to @wordpress-gcb/fields, usable without the GCB plugin.

Maintainers

Package info

github.com/wordpress-gcb/gcb-fields-php

Homepage

pkg:composer/wordpress-gcb/fields

Statistics

Installs: 25

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

0.2.0 2026-06-05 18:01 UTC

This package is not auto-updated.

Last update: 2026-06-06 16:41:32 UTC


README

Turn a GCB block.fields.json controls schema into a WordPress block attribute schema, in PHP, with no dependency on the GCB plugin. The server-side companion to @wordpress-gcb/fields (npm).

Part of GCB — Gutenberg Control Blocks.

Install

composer require wordpress-gcb/fields

Usage

use GCBFields\Schema;

$controls = json_decode(
    file_get_contents( __DIR__ . '/blocks/hero/block.fields.json' ),
    true
)['controls'];

register_block_type( __DIR__ . '/blocks/hero', [
    'attributes' => Schema::attributes( $controls ),
] );

Schema::attributes() returns the { type, default } map WordPress expects — structural controls (group/panel/tools-panel) are skipped, control types map to the right attribute type, and each gets a sensible default (overridable per control via attributeType / default).

API

  • Schema::attributes(array $controls): array — full controls → attributes map.
  • Schema::attribute_type(string $controlType): string — one control type → string|number|boolean|array|object.
  • Schema::default_value(string $attributeType): mixed — the empty default for a type.

Links

License

GPL-2.0-or-later