PHPackages                             bernskioldmedia/block-plugin-support - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. bernskioldmedia/block-plugin-support

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bernskioldmedia/block-plugin-support
====================================

A reusable way of adding block support to a WordPress plugin.

2.1.1(4y ago)12.8kMITPHPPHP ^7.4|^8.0

Since Apr 24Pushed 4y ago1 watchersCompare

[ Source](https://github.com/bernskiold/Block-Plugin-Support)[ Packagist](https://packagist.org/packages/bernskioldmedia/block-plugin-support)[ RSS](/packages/bernskioldmedia-block-plugin-support/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)DependenciesVersions (23)Used By (0)

**THIS REPOSITORY WILL GO INTO READ-ONLY MODE**

We have integrated this composer package into our wp-plugin-base instead of keeping it separate.

Block Plugin Support
====================

[](#block-plugin-support)

We find ourselves increasingly creating a bunch of plugins that add one or more blocks to the block editor.

This requires a few functions to load and register. And since we use the same scaffold almost any time, it makes sense to split out the block part into a library.

The library consists of a simple trait for making the plugin support blocks and two abstract classes for a base server-side rendered block.

Getting started
---------------

[](#getting-started)

All you need to do is include the `Has_Blocks` trait in the plugin class as long as you are using the latest version of our plugin base, which recognizes this trait automatically.

Blocks are assumed to be placed in a `blocks` subfolder, and they are being built to `dist/blocks`.

**This trait relies on an autoloader being used in the plugin!**

```
use BernskioldMedia\WP\Block_Plugin_Support\Traits\Has_Blocks;

class My_Plugin {

    use Has_Blocks;

}

```

### Defining a custom block prefix

[](#defining-a-custom-block-prefix)

The trait will default to using the 'bm' prefix for blocks. Blocks are named with a prefix to scope them to the project they are a part of. This also influences how the script and style handles are registered ($prefix-block-$block\_name).

Your project probably requires its custom prefix. You can set it on the main plugin class like so:

```
use BernskioldMedia\WP\Block_Plugin_Support\Traits\Has_Blocks;

class My_Plugin {

    use Has_Blocks;

    // Set my custom block prefix.
    protected static string $block_prefix = 'my-prefix';

}

```

Required Folder Structure
-------------------------

[](#required-folder-structure)

The trait assumes the following folder structure:

`blocks/` is the location of all blocks with one folder per block. The `index.js` file in each block folder is the entrypoint for the build script.

`dist/blocks` is the location of built JavaScript blocks with the same filename as the main folder name.

`languages/` is the location of the translation files. The handle and domain are both set to `{$block_prefix}-{$block_name}`.

Required Methods
----------------

[](#required-methods)

The trait relies on two methods to be implemented.

- `get_url()` should return the URL to the plugin directory.
- `get_path()` should return the path to the plugin directory.
- `get_textdomain()` should return the string plugin textdomain.

Hooks &amp; Filters
-------------------

[](#hooks--filters)

We strive to make all code easily customizable with plenty of filters and hooks as needed. You never know when or why you might need that simple one-off customization.

Since this is a composer package, filters are housed inside of the "package namespace" and do not inherit the consumer plugin's own naming structure.

Filters
-------

[](#filters)

`bm_block_support_{$BLOCKNAME}_wrapper_args`. Available for any dynamic block that extends `Block` and is reliant on `Block::$name` being set in the consuming dynamic block class. Allows you to customize the args sent to `get_block_wrapper_attributes`.

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 93.9% 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 ~35 days

Recently: every ~70 days

Total

22

Last Release

1476d ago

Major Versions

0.1.3 → 1.0.02020-04-25

1.4.4 → 2.0.02021-07-24

PHP version history (3 changes)0.1.3PHP ^7.1

1.4.3PHP ^7.1|^8.0

1.4.4PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/51986177e3badf5ae6cd008a309befe4ec88264bd518c1a623bd33f5cebc0fc5?d=identicon)[bernskiold](/maintainers/bernskiold)

---

Top Contributors

[![ErikBernskiold](https://avatars.githubusercontent.com/u/1166728?v=4)](https://github.com/ErikBernskiold "ErikBernskiold (62 commits)")[![annlickander](https://avatars.githubusercontent.com/u/1032697?v=4)](https://github.com/annlickander "annlickander (4 commits)")

---

Tags

traitwordpresswordpress-gutenbergwordpress-helperswordpress-plugin-library

### Embed Badge

![Health badge](/badges/bernskioldmedia-block-plugin-support/health.svg)

```
[![Health](https://phpackages.com/badges/bernskioldmedia-block-plugin-support/health.svg)](https://phpackages.com/packages/bernskioldmedia-block-plugin-support)
```

PHPackages © 2026

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