alleyinteractive/wp-match-blocks
A WordPress utility for matching Gutenberg blocks in post content. Detect whether a post contains a given block type or attributes, so themes and plugins can conditionally load assets or change rendering based on the blocks actually used.
alleyinteractive/wp-match-blocks gives PHP a reliable way to walk Gutenberg block trees server-side. That underpins a real product decision: render WordPress-authored content inside a Laravel app (Blade/Inertia/Livewire) rather than proxying the WP front-end theme. It is the plumbing that makes "WordPress as a CMS, Laravel as the product" credible instead of a regex-driven hack.post_content and rewrite it safely. This package is the traversal layer for that work — the difference between a scripted migration you can run in a queued job and a manual editorial sweep.parse_blocks() is WordPress-provided, but recursive matching and safe re-serialization is ~100–200 lines of fiddly, edge-case-heavy code (nesting, inner blocks, whitespace, escaping). Adopting a small maintained package is cheaper than owning that logic — provided the maintenance signal holds.Adopt it when all of the following are true:
<!-- wp:... -->) and need to inspect or transform it server-side in PHP, not in JS.Look elsewhere or build in-house when:
parse_blocks() plus a short recursive helper is less total risk than a dependency.@wordpress/blocks) and PHP only ever stores opaque markup.block.json schemas or full block rendering — this is traversal, not a validator or renderer. Pair it with WordPress's server-side renderer or handle rendering yourself.To executives: This is a small, single-purpose open-source library that lets our PHP application read and safely rewrite WordPress block content. It supports a strategic option we keep evaluating — using WordPress purely as an authoring tool while our Laravel product owns the experience — and it de-risks content migrations by replacing hand-rolled parsing code with something tested. The v4.4.0 release is a routine minor update: no breaking changes, no deprecations, no new surface area. Cost is negligible; the real cost is the WordPress runtime dependency, which we should accept deliberately rather than by accident.
To engineering: wp-match-blocks (Alley Interactive) provides recursive block matching and block escaping over parsed block arrays. It replaces ad-hoc regex and hand-written tree walks in our content pipeline — the code most likely to silently corrupt posts during a migration. Composer-installable, narrow API, easy to wrap behind our own BlockRepository interface so we can swap it out. Two cautions: (1) it assumes WordPress block-parser primitives are available, so containerize that; (2) release notes for v4.4.0 are changelog-link-only, so review the diff, pin the version, and cover our usage with contract tests before upgrading. If the dependency ever looks stale, the wrapper makes a fork or in-house replacement a contained, sub-day change.
How can I help you explore Laravel packages today?