Learn the toolkit by building a content importer
Across four chapters and roughly forty-five minutes, you'll build a small WordPress content importer in pure PHP. It reads a folder of Markdown posts, rewrites the HTML inside them, packages everything as a ZIP-backed staging filesystem, and finally emits a WXR file ready to feed to WordPress's importer. Every snippet runs in your browser. You finish with code you can keep.
Before you start
You should be comfortable reading and writing PHP. You don't need to know WordPress internals — we'll explain the WordPress-specific bits as they come up. You don't need anything installed locally; the runnable snippets execute via WordPress Playground in the page.
If you want to run the same code on your own machine afterwards, every example works under PHP 7.2 or newer with composer require wp-php-toolkit/<component>.
The path
- Quickstart Five minutes from zero to a runnable HTML rewrite. The shape of every later chapter, in miniature.
-
Chapter 1 — Rewriting HTML safely
Add
loading="lazy"to images, rewrite relative links, strip script tags. Meet the cursor model that underlies every later chapter. - Chapter 2 — Streaming archives Read your importer's input from a ZIP without buffering it in memory. Compose a ZIP-backed filesystem with a memory-backed staging filesystem.
- Chapter 3 — Markdown to blocks to WXR Turn each Markdown file into block markup, then assemble those blocks into a WordPress eXtended RSS export.
- Chapter 4 — Talking to the network Frontload the images referenced from the imported posts using HttpClient with progress, redirects, and resumable downloads.
- Recap What you can now do, and where the rest of the toolkit lives.
What you're building
By the end of chapter 4, you'll have a small command — call it importer.php — that takes a ZIP file of Markdown posts and produces a WordPress WXR file:
$ php importer.php posts.zip > export.xml
parsed 12 posts, 8 images
rewrote 47 inline links
fetched 8 image attachments (2.3 MB)
wrote export.xml (94 KB, valid WXR 1.2)
It's a real tool — the WordPress importer plugin will accept the output. You'll write it in pieces, one component per chapter, and the canonical example file grows with each chapter. By chapter 4 it's a hundred lines of pure PHP that depends on no extension beyond json and mbstring.
The actual content — twelve Markdown posts about cooking, with embedded images and frontmatter — is part of the tutorial's example data and ships pre-loaded into every snippet. You'll see it in chapter 1.