Skip to content

Automatically bootstrap interactive PHP snippets - #278

Draft
sirreal wants to merge 1 commit into
masterfrom
runnable-snippets-default-wp-loaded
Draft

Automatically bootstrap interactive PHP snippets#278
sirreal wants to merge 1 commit into
masterfrom
runnable-snippets-default-wp-loaded

Conversation

@sirreal

@sirrealsirreal commented Aug 14, 2026

Copy link
Copy Markdown
Member

Summary

  • automatically add the WordPress bootstrap preamble to exported interactive PHP snippets
  • let documentation authors omit <?php and require '/wordpress/wp-load.php'; from examples
  • normalize snippets that already contain an opening tag or the full preamble without duplicating either

Follow-up to #258

Context

This follows up on feedback from the review of #258 and the subsequent default-Blueprint discussion.

Interactive snippets execute as standalone PHP programs and need WordPress loaded, but the exporter previously copied fenced code verbatim. That forced every WordPress example to repeat execution boilerplate. The exporter now supplies that boilerplate while keeping the authored examples focused on the API being demonstrated.

Testing

  • vendor/bin/phpunit
  • 150 tests, 401 assertions

@sirreal

Copy link
Copy Markdown
MemberAuthor

I'm wondering if this is the right place to do this 🤔

Here, I do think we can inject <?php\n which seems like it will be necessary.

The web component has some configuration options and I think we should be able to configure it to require '/wordpress/wp-load.php'; before evaluating the snippet.

@adamziel Thoughts? A basic snippet should really not require 2 lines of bootstrap:

-<?php-require '/wordpress/wp-load.php';
echo esc_html( '<>' );

Sign up for freeto 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.

1 participant

@sirreal