Skip to content

Add wp bs blocks render to smoke-test blocks for PHP problems - #188

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/cli-blocks-render
Oct 26, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:feat/cli-blocks-render

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

A theme that wants to check its block templates against the installed Blockstudio has to write its own script today: build the block markup, run do_blocks() and collect notices with set_error_handler(). Blockstudio has wp bs blocks validate for stored content, but nothing that renders. We wrote such a script for our theme's CI, and it found templates that warned on repeater rows without a saved key, which a stubbed render could not see.

This adds wp bs blocks render [<name>...] [--attributes=<json>|@<file>] [--format=<table|json>]:

  • Each block renders through do_blocks() from a block comment carrying blockstudio.attributes, the shape the editor stores and the path a page takes, without a queried post. Nothing is written to the database.
  • Without names every registered block renders. The values are the example.attributes of the block.json (what the inserter preview uses); a block without an example renders with its field defaults and the output says so. Image placeholders that only exist for the inserter preview are skipped.
  • --attributes replaces the example for one block, as a JSON object of field values or @file, so CI can reach branches the example does not.
  • Notices, warnings, deprecations and thrown errors are collected with file and line; repeats are reported once, @-silenced calls are ignored, and the error handler and error_reporting are restored afterwards.
  • Exit code 1 when anything was reported, otherwise 0. Unknown blocks, invalid --attributes and unknown formats are errors, in the style of validate.

Real output from a test theme in WordPress Playground:

$ wp bs blocks render
smoke/deprecated: no example attributes, rendered with field defaults.
smoke/no-example: no example attributes, rendered with field defaults.
| block               | case     | level      | message                                                                       | file                                                                         | line |
| smoke/deprecated    | defaults | Deprecated | strlen(): Passing null to parameter #1 ($string) of type string is deprecated | /wordpress/wp-content/themes/smoke-theme/blockstudio/deprecated/index.php    | 1    |
| smoke/undefined-key | example  | Warning    | Undefined array key "subtitle"                                                | /wordpress/wp-content/themes/smoke-theme/blockstudio/undefined-key/index.php | 2    |

The logic lives in a small Render_Check class so it can be tested without WP-CLI (@since 7.7.9, adjust to the release). The command is documented in docs/docs/dev/cli.md next to validate, and the LLM bundle is rebuilt. WordPress raises its own deprecation notices only with WP_DEBUG on, so the docs suggest enabling it in CI.

Tests: tests/unit/cli/RenderCheckTest.php (example, defaults, --attributes, image placeholders, undefined key with file, line and de-duplication, @, deprecation, thrown error leaves no open buffer, handler restored): 9 tests pass in WordPress Playground (PHP 8.4, PHPUnit 11.5). The command was also run through real WP-CLI there for all blocks, named blocks, --attributes inline and from a file, both formats and the error paths. Lint, format, typecheck, docs, schemas, i18n, PHPCS and PHPStan pass locally; the full suite is left to CI.

@dnnsjsk
dnnsjsk merged commit 2720009 into inline0:main Oct 26, 2026
@dnnsjsk

dnnsjsk commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Released in Blockstudio 7.7.9. Thanks for the contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants