-
Notifications
You must be signed in to change notification settings - Fork 262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Data liberation] wp_rewrite_urls() #1893
Merged
Merged
Conversation
This file contains 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
adamziel
changed the title
[Data liberation] Prototype wp_rewrite_urls()
[Data liberation] wp_rewrite_urls()
Oct 14, 2024
48 tasks
I thought it won't be ready for some more time but I today landed a comfortable enough amount of unit tests to merge this PR as v1 of |
adamziel
added a commit
that referenced
this pull request
Oct 28, 2024
A part of #1894. Follows up on #1893. This PR brings in a few more PHP APIs that were initially explored outside of Playground so that they can be incubated in Playground. See the linked descriptions for more details about each API: * XML Processor from WordPress/wordpress-develop#6713 * Stream chain from adamziel/wxr-normalize#1 * A draft of a WXR URL Rewriter class capable of rewriting URLs in WXR files ## Testing instructions * Confirm the PHPUnit tests pass in CI * Confirm the test suite looks reasonabel * That's it for now! It's all new code that's not actually used anywhere in Playground yet. I just want to merge it to keep iterating and improving.
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.
Motivation for the change, related issues
A part of #1894.
Prototypes a
wp_rewrite_urls()
URL rewriter for block markup to migrate the content from, say,<a href="https://adamadam.blog">
to<a href="https://adamziel.com/blog">
.Status:
WP_HTML_Tag_Processor
andWP_HTML_Processor
to enable usage outside of WordPress core.Details
This PR consists of a code ported from https://github.com/adamziel/site-transfer-protocol. It uses a cascade of parsers to pierce through the structured data in a WordPress post and replace the URLs matching the requested domain.
The data flow is as follows:
Parse HTML -> Parse block comments -> Parse attributes JSON -> Parse URLs
On a high level, this parsing cascade is handled by the
WP_Block_Markup_Url_Processor
class:Getting more into details, the
WP_Block_Markup_Url_Processor
extends theWP_HTML_Tag_Processor
class and walks the block markup token by token. It then drills down into:<a href="">
, looking for ones that contain valid URLsThe
next_url()
method moves through the stream of tokens, looking for the next match in one of the above contexts, and theset_raw_url()
knows how to update each node type, e.g. block attributes updates arejson_encode()
-d.Processing tricky inputs
When this code is fed into the migrator:
This actual output is produced:
Remaining work
composer install
)Follow-up work
WP_HTML_Tag_Processor
in WordPress core, see HTML API: Add set_modifiable_text() for replacing text nodes. wordpress-develop#7007 (comment)WP_HTML_Tag_Processor
as a "WordPress polyfill" for standalone usage.Testing Instructions (or ideally a Blueprint)
CI runs the PHP unit tests. To run this on your local machine, do this: