Add wp post convert-to-blocks for server-side block conversion - #655
Draft
swissspidy wants to merge 1 commit into
Draft
swissspidy wants to merge 1 commit into
swissspidy wants to merge 1 commit into
Conversation
Adds a `post convert-to-blocks <id>... [--dry-run]` subcommand that turns classic post content into block markup using the server-side conversion from WordPress/gutenberg#82013 (`gutenberg_html_to_block_markup()`). Posts that cannot be found count as failures, posts without content or that already contain blocks are skipped, and the run ends with the usual batch summary. Without that Gutenberg build active, the command fails with a clear error pointing at the pull request. Only the "not available" scenario runs in CI; the scenarios that need the Gutenberg build are tagged @broken with instructions for running them locally. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ECHX5L8q3jXJTxQqX94rH7
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: trueThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds a
wp post convert-to-blocks <id>... [--dry-run]subcommand that converts classic (non-block) post content to block markup.What the command does
For each ID, in order:
post_content: warningPost <id> has no content to convert., counted as skipped.Post <id> already contains blocks., counted as skipped.gutenberg_html_to_block_markup(). With--dry-runit logsWould convert post <id>.and saves nothing. Without it, the markup is saved withwp_update_post(); aWP_Erroris a warning and a failure, otherwiseConverted post <id>.is logged.The run ends with the usual batch summary from
report_batch_operation_results()(Success: Converted 3 of 4 posts (1 skipped)., orError: Only converted ...with a non-zero exit when any post failed). Dry runs use the same shape withWould convert ...wording, following thewp term prune --dry-runprecedent in this repository.The docblock notes that the conversion itself does not sanitise: saving goes through the usual kses filtering for the current user, so a run without
--useris filtered as an untrusted author would be, and--user=<administrator>keeps markup that needsunfiltered_html.Changes
src/Post_Command.php: newconvert_to_blocks()subcommand (docblock,get_flag_value, the existing post fetcher,Block_Processor_Helper::has_blocks()andreport_batch_operation_results()).composer.json: registerspost convert-to-blocksinextra.commands.README.md: regenerated withwp scaffold package-readme(additions only).features/post-convert-to-blocks.feature: new feature file.Tests
Runs in CI today: the first scenario runs on a plain
Given a WP installand asserts the "not available" error on STDERR with exit code 1.Needs the Gutenberg build from PR 82013 (tagged
@broken, so CI skips them): a real conversion of<h2>Title</h2><p>Text</p>into<!-- wp:heading -->/<!-- wp:paragraph -->markup,--dry-runleaving the content untouched, skipping posts that already contain blocks, skipping empty content, and a missing post reported as a failure with exit code 1. The feature file's header comment explains how to run them locally: build the plugin ZIP from that branch, remove the@brokentags, and addAnd I run \wp plugin install /path/to/gutenberg.zip --activate`afterGiven a WP install`.Validation
composer lint,composer phpcsandcomposer lint-gherkin: clean.composer phpstan: no findings in the changed files. The two pre-existingignore.unmatchedIdentifierreports insrc/User_Session_Command.phpalso appear onmainin my environment and are unrelated.WP_CLI_TEST_DBTYPE=sqliteagainst WordPress 7.1. The CI-safe scenario passes.@brokenscenarios were also exercised locally against the PHP from PR 82013 (itslib/experimental/block-transforms/andlib/compat/wordpress-7.2/block-type-transforms.phploaded through an mu-plugin, with thetransformsfrom the PR'sblock.jsonfiles applied to the registered core block types, since a JS build was not possible in my environment). All five pass that way; the "not available" scenario correctly fails under that harness because the function then exists.🤖 Generated with Claude Code
https://claude.ai/code/session_01ECHX5L8q3jXJTxQqX94rH7
Generated by Claude Code