PHP Toolkit

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 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-style export stream. Most snippets run in your browser; network-bound examples are marked local-only. 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, the examples target PHP 7.2 or newer with composer require wp-php-toolkit/<component>, plus any optional extension used by the chosen component.

The path

  1. Quickstart Five minutes from zero to a runnable HTML rewrite. The shape of every later chapter, in miniature.
  2. Chapter 1 — Rewriting HTML safely Add loading="lazy" to images, rewrite relative links, and neutralize scripts and inline handlers. Meet the cursor model that underlies every later chapter.
  3. 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.
  4. Chapter 3 — Markdown to blocks to WXR Turn each Markdown file into block markup, then assemble those blocks into a WordPress eXtended RSS export.
  5. Chapter 4 — Talking to the network Frontload images before import using HttpClient with progress, redirects, and resumable downloads.
  6. 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)

It's a real tool, but the tutorial keeps the export writer deliberately small: if you're targeting the WordPress importer plugin directly, add the importer-required channel metadata such as wp:wxr_version. 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 PHP using toolkit components that avoid libxml2, libzip, and mandatory curl.

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.

Start the quickstart →