PHPackages                             ralfhortt/wp-block - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ralfhortt/wp-block

ActiveLibrary[API Development](/categories/api)

ralfhortt/wp-block
==================

A composer wrapper for registering WordPress blocks.

3.2.0(2mo ago)0814↓81.8%[2 PRs](https://github.com/Horttcore/wp-block/pulls)GPL-2.0-or-laterPHPCI passing

Since Jan 18Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Horttcore/wp-block)[ Packagist](https://packagist.org/packages/ralfhortt/wp-block)[ RSS](/packages/ralfhortt-wp-block/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (7)Dependencies (12)Versions (13)Used By (0)

WP Block
========

[](#wp-block)

[![Tests](https://github.com/Horttcore/wp-block/actions/workflows/tests.yml/badge.svg)](https://github.com/Horttcore/wp-block/actions/workflows/tests.yml)[![Code Quality](https://github.com/Horttcore/wp-block/actions/workflows/code-quality.yml/badge.svg)](https://github.com/Horttcore/wp-block/actions/workflows/code-quality.yml)[![Security](https://github.com/Horttcore/wp-block/actions/workflows/security.yml/badge.svg)](https://github.com/Horttcore/wp-block/actions/workflows/security.yml)[![codecov](https://camo.githubusercontent.com/d4367212c5b763c9d286ac4ea3235a8a4709a10758afd7bde5c672410010bead/68747470733a2f2f636f6465636f762e696f2f67682f486f727474636f72652f77702d626c6f636b2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/Horttcore/wp-block)

A modern, fluent PHP wrapper for WordPress block development.

Installation
------------

[](#installation)

```
composer require ralfhortt/wp-block
```

Features
--------

[](#features)

- 🚀 **BlockManifest** - Register multiple blocks from manifest files
- 🎨 **BlockVariations** - Create variations of existing blocks
- 🎭 **BlockStyles** - Manage block styles
- ⚙️ **BlockDefaults** - Override block attribute defaults with callback support
- 🛠️ **BlockSupports** - Configure block supports (enable/disable features)
- 📦 **BlockManager** - Unified management of supports, styles, and variations per block
- 🧩 **Block** - Custom PHP-rendered blocks

Quick Start
-----------

[](#quick-start)

### BlockManifest

[](#blockmanifest)

Register blocks from a manifest file (recommended for modern block development):

```
use RalfHortt\WPBlock\BlockManifest;

(new BlockManifest(__DIR__ . '/build/blocks/blocks-manifest.php'))->register();
```

### BlockDefaults

[](#blockdefaults)

Override default attribute values with support for dynamic callbacks:

```
use RalfHortt\WPBlock\BlockDefaults;

// Static defaults
BlockDefaults::for('core/image')
    ->set('sizeSlug', 'large')
    ->set('linkDestination', 'media')
    ->register();

// Dynamic defaults with callbacks
BlockDefaults::for('core/image')
    ->set('sizeSlug', fn($metadata) => wp_is_mobile() ? 'thumbnail' : 'large')
    ->register();

// Multiple blocks with shared and individual defaults
BlockDefaults::for(['core/image', 'core/paragraph'])
    ->set('className', 'custom-block') // Both blocks
    ->set('core/image', 'sizeSlug', 'large') // Only core/image
    ->register();
```

### BlockVariations

[](#blockvariations)

Create variations of existing blocks:

```
use RalfHortt\WPBlock\BlockVariations;

(new BlockVariations([
    'core/image' => [
        [
            'name' => 'hero-image',
            'title' => __('Hero Image'),
            'attributes' => [
                'align' => 'wide',
                'className' => 'hero-image',
            ],
        ],
    ],
]))->register();

// Or use fluent interface
(new BlockVariations())
    ->addVariation('core/button', [
        'name' => 'cta-button',
        'title' => __('CTA Button'),
        'attributes' => ['className' => 'cta-button'],
    ])
    ->removeVariation('core/button', 'outline')
    ->register();
```

### BlockStyles

[](#blockstyles)

Remove unwanted block styles:

```
use RalfHortt\WPBlock\BlockStyles;

(new BlockStyles())
    ->removeStyle('core/button', 'outline')
    ->removeAllStyles('core/separator')
    ->register();
```

> **Note:** For adding styles, use `theme.json` or `block.json` instead.

### BlockSupports

[](#blocksupports)

Configure block supports (enable/disable block features):

```
use RalfHortt\WPBlock\BlockSupports;

// Add supports
BlockSupports::for('core/image')
    ->add(['color' => true, 'alignment' => true])
    ->register();

// Add supports with nested configuration
BlockSupports::for('core/button')
    ->add([
        'color' => [
            'palette' => [
                ['name' => 'Red', 'slug' => 'red', 'color' => '#ff0000'],
            ],
        ],
    ])
    ->register();

// Remove supports
BlockSupports::for('core/image')
    ->remove(['spacing', 'padding', 'margin'])
    ->register();

// Combine add and remove
BlockSupports::for('core/paragraph')
    ->add(['color' => true, 'typography' => true])
    ->remove(['spacing'])
    ->register();
```

**Note:** When both adding and removing the same support, removals take precedence.

### BlockManager

[](#blockmanager)

Manage supports, styles, and variations for a specific block in one place:

```
use RalfHortt\WPBlock\BlockManager;

$manager = new BlockManager('core/image');

// Configure supports
$manager->addSupports(['color' => true, 'alignment' => true]);
$manager->removeSupports(['spacing']);

// Configure styles (no need to repeat block name!)
$manager->removeStyle('outline');

// Configure variations (no need to repeat block name!)
$manager->addVariation([
    'name' => 'hero-image',
    'title' => 'Hero Image',
    'attributes' => ['align' => 'wide'],
]);

// Register all managers
$manager->register();
```

Or use fluent chaining for a more compact syntax:

```
(new BlockManager('core/button'))
    ->addSupports(['color' => true])
    ->removeStyle('outline')
    ->addVariation(['name' => 'cta', 'title' => 'CTA Button'])
    ->register();
```

The BlockManager provides direct access to all methods from BlockSupports, BlockStyles, and BlockVariations with a unified fluent interface. Style and variation methods automatically use the managed block name, eliminating redundancy.

### Custom Block Class

[](#custom-block-class)

Create custom PHP-rendered blocks:

```
use RalfHortt\WPBlock\Block;

class MyBlock extends Block {
    protected string $name = 'myplugin/custom-block';
    protected string $title = 'My Custom Block';
    protected string $blockJson = 'block.json';

    public function render(array $attributes, string $content): string {
        return '' . esc_html($attributes['title'] ?? '') . '';
    }
}

(new MyBlock())->register();
```

API Reference
-------------

[](#api-reference)

### Block Variation Properties

[](#block-variation-properties)

Each variation supports these properties:

- `name` (required) - Unique identifier
- `title` - Display name in block inserter
- `description` - Description text
- `attributes` - Default attribute values
- `innerBlocks` - Default inner blocks for containers
- `scope` - Where variation appears: `['inserter']`, `['block']`, or both
- `isDefault` - Set as default variation

See [WordPress Block Variations documentation](https://developer.wordpress.org/block-editor/reference-guides/block-api/block-variations/) for more details.

### Available Hooks

[](#available-hooks)

**Block Class:**

- `{$blockName}/before` - Action before block output
- `{$blockName}/after` - Action after block output
- `{$blockName}/render` - Filter render callback

**WordPress Filters (used internally):**

- `block_type_metadata` - Used by BlockDefaults and BlockManifest
- `block_type_metadata_settings` - Used by BlockVariations and BlockStyles
- `get_block_type_variations` - Used by BlockVariations
- `register_block_type_args` - Used by BlockSupports

Development
-----------

[](#development)

### Requirements

[](#requirements)

- PHP 8.3 or higher
- Composer

### Testing

[](#testing)

```
composer install
composer test              # Run tests
composer test:coverage     # With coverage
composer phpstan           # Static analysis
composer ci                # Full CI suite
```

### Code Quality

[](#code-quality)

- **PestPHP** for testing
- **PHPStan** (level 8) for static analysis
- **GitHub Actions** for CI/CD
- **Brain\\Monkey** for WordPress mocking

Changelog
---------

[](#changelog)

See [CHANGELOG.md](CHANGELOG.md) for version history and migration guides.

License
-------

[](#license)

MIT License - see LICENSE file for details.

Credits
-------

[](#credits)

Developed and maintained by [Ralf Hortt](https://horttcore.de).

###  Health Score

47

—

FairBetter than 93% of packages

Maintenance85

Actively maintained with recent releases

Popularity16

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 81.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~283 days

Recently: every ~40 days

Total

9

Last Release

82d ago

Major Versions

1.2.1 → 2.0.02025-10-11

2.4 → 3.1.02026-02-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/45d54752dcf3da868ffe4a5ad2b876d6acb911fd914700b52e4d4777ff7d4a02?d=identicon)[Ralf Hortt](/maintainers/Ralf%20Hortt)

---

Top Contributors

[![Horttcore](https://avatars.githubusercontent.com/u/503252?v=4)](https://github.com/Horttcore "Horttcore (31 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")

---

Tags

composermodulewordpress

###  Code Quality

TestsPest

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ralfhortt-wp-block/health.svg)

```
[![Health](https://phpackages.com/badges/ralfhortt-wp-block/health.svg)](https://phpackages.com/packages/ralfhortt-wp-block)
```

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

93452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
