Search by

itsjustvita / laravel-wp-migrator

itsjustvita

Migrate a WP site's content into a clean Laravel application: posts, media, terms, menus, users, SEO meta and redirects, with block parsing and a theme inventory.

Package info

github.com/itsjustvita/laravel-wp-migrator

pkg:composer/itsjustvita/laravel-wp-migrator

Statistics

Installs: 24

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v1.7.0 2026-11-28 11:20 UTC

This package is auto-updated.

Last update: 2026-11-28 12:18:48 UTC


README

CI

Move a WP site's content into a clean Laravel application without losing data, URLs or rankings.

The package migrates posts, pages, custom post types, media, taxonomies, menus, users and comments into its own schema, parses block, classic and Elementor content into a renderable structure, imports SEO meta and custom fields, keeps old URLs alive through redirects, and lets existing users keep their passwords. It does not convert theme or plugin code. Instead, it produces an inventory of the theme and a migration plan for rebuilding the frontend in Blade.

wp:check on a demo site with planted traces of a hack: the administrators, suspicious content and content that is not migrated

php artisan wp:check on a demo site with planted traces of a hack.

Status: stable since 1.0. Breaking changes to the public API come only with a new major version, see Versioning and the changelog.

Requirements

  • PHP 8.3 or newer
  • Laravel 12 or 13
  • Read access to the source database (WP 5.0 or newer, single site)

Installation

composer require itsjustvita/laravel-wp-migrator

Publish the configuration file:

php artisan vendor:publish --tag=wp-migrator-config

Then add a connection for the source database to config/database.php and point WP_MIGRATOR_CONNECTION at it. The package only ever reads from that connection.

Publish and run the migrations:

php artisan vendor:publish --tag=wp-migrator-migrations
php artisan migrate

Usage

Check the connection and paths, and see what the site contains:

php artisan wp:check

Import the content. The importers run in dependency order: users, media, terms, posts, menus, comments and redirects.

php artisan wp:import
php artisan wp:import --dry-run
php artisan wp:import --only=users,media
php artisan wp:import --type=event --since=2026-10-01
php artisan wp:import --prune
Option Effect
--only Comma-separated importers: users, media, terms, posts, pages, menus, comments, redirects. posts covers every post type except pages.
--type Comma-separated post types to import.
--since Only posts and media modified on or after this date.
--dry-run Rolls every change back at the end and copies no files.
--force Maps rows again even when they are unchanged, for example after changing the configuration.
--prune Also removes what an earlier run imported and the old site no longer has. Not together with --only or --type.

Imports are idempotent. Unchanged rows are skipped, changed rows are updated, and an aborted run can simply be started again. A post that refers to a post imported later in the same run is mapped once more at the end of the run. Whatever still cannot be resolved is mapped again on the next run. Every run writes a report to storage/logs/wp-migrator-<timestamp>.md.

Content that was deleted on the old site stays in the application until an import runs with --prune. It removes what an earlier run imported and the import no longer reads, because it was deleted or trashed on the old site or because the configuration leaves it out since: posts, pages and other post types, media with their files, terms, menus, menu items and comments. Their SEO data goes with them, as do the menu items that link to them and the redirects to URLs that nothing else has. Three kinds of records stay:

  • Users are never deleted, since the accounts belong to the application. The report warns about each account that is gone from the old site, because it can still log in.
  • Records the import only linked, such as a user that already existed, are left alone.
  • A record that several rows of the old site were merged into stays until the last of them is gone.

The models of custom mappers are deleted through Eloquent, so model events and soft deletes apply. --prune compares everything that was imported with the whole site, which is why it cannot be combined with --only or --type. In a terminal it lists how many records of each kind are about to go and asks first. With --no-interaction it removes them without asking; a script that passes neither a terminal nor that option removes nothing. --dry-run --prune removes nothing and lists in the report what would go.

The pages below a removed page move to the top level, which changes their URLs. Run wp:import --force afterwards, so menus and links in the content follow.

Media files are only copied when their extension is listed in media.allowed_extensions. Files a web server could execute, such as .php, are never copied, also not behind a second extension like shell.php.jpg: hacked sites often hide a backdoor in their uploads. SVG and HTML files can run script in the browser and are left out by default.

Migration plan

The theme is not converted, it is read. wp:inventory scans the theme and the source database and writes a plan for rebuilding the frontend in Blade:

php artisan wp:inventory
php artisan wp:inventory --theme=/path/to/wp-content/themes/acme --child=/path/to/wp-content/themes/acme-child
php artisan wp:inventory --output=docs/plan.md --force

Without --theme it looks for the active theme, and its parent if it is a child theme, in the themes directory next to source.uploads_path. The plan goes to docs/wp-migration-plan.md, and an existing plan is only replaced with --force, since you may have ticked off items in it.

The plan is a Markdown checklist for whoever builds the new frontend:

  • the administrator accounts to review before the import, and signs of a hack in the content, the options and the uploads
  • routes and views for the front page, every post type and its archive, pages with their own template, page templates with the posts that use them, and the category, tag, author and custom taxonomy archives, following the URL patterns in the configuration; a site without posts gets no category, tag and author archives
  • post types without pages of their own, such as form entries, which you may want to leave out of the import
  • components for headers, footers, sidebars and template parts, and the menu locations with the menus assigned to them
  • shortcodes and blocks that have no handler or view yet, with how often and where the content uses them
  • active plugins, or the installed ones when none is active, sorted into those the import covers, those that need a replacement and those that are not needed in Laravel
  • scripts and styles to move to Vite, the theme features, and the content that is not migrated

The theme is never run. PHP files are parsed, and only values written literally in the code are read, so a register_post_type($type) with a computed name is listed at the end of the plan to check by hand. When the source database cannot be read, the plan is written from the theme alone.

Scaffolding the frontend

wp:scaffold turns the migration plan into a working start for the frontend:

php artisan wp:scaffold
php artisan wp:scaffold --force   # also replace files that exist

It reads the theme and the source database like wp:inventory, and the imported content, and writes:

  • routes/wp.php with routes from the URL patterns, and a line in routes/web.php that loads it
  • app/Http/Controllers/WpController.php for the front page, single posts and pages, archives, taxonomy and author archives and search, and app/Support/WpUrl.php for links to posts and terms
  • views under the names the migration plan uses, such as pages/show, events/show and posts/index, each noting the theme file it replaces
  • the layout layouts/wp with the SEO tags, a layout for each page template, and components for the header, the footer and the menus of the theme's locations
  • a view for each block without one; for Elementor widgets it lists the settings the imported widgets hold. The blocks of WooCommerce get none, since the shop is not migrated

Run it after the import. The files belong to your application: change them as you like, wp:scaffold keeps files that exist unless you pass --force. Names from the old site end up in code, and a hacked site controls them, so post types, taxonomies, menu locations, author slugs and widget settings whose names do not match the key formats of WP are left out with a note, and every other text is escaped. The views of widgets print their fields escaped; print fields whose HTML you trust with {!! !!}.

The routes are loaded at the end of routes/web.php, so the front page replaces an earlier route for /, such as the welcome page of a new application. The page shown there has this one address: the route for pages redirects its own slug to /. A route for / that you define after that line wins instead, and the command says so.

The imported users keep no slug, so the controller lists the authors that have posts, each slug with the ID the user had on the old site, and finds the user through the import map. Scaffold again with --force when authors were added, or use {id} in urls.author_pattern, which needs no list.

Suspicious content

Agencies are often asked to move a site after it was hacked. The import keeps the HTML of the content as it is, so injected code would come along. wp:check, the import report and the migration plan therefore list signs of a hack:

  • in the content that is imported, including Elementor data: scripts with the hosts they load from, event handlers such as onerror, links that run script (javascript:, vbscript:, data:text/html), frames from sites other than common players and maps, links hidden with CSS, and obfuscated code such as eval(, atob( or base64_decode(, except inside <pre> and <code>
  • code in options, which are not imported but often hold a backdoor's settings
  • program files such as .php in the uploads directory, which the import never copies

Nothing is changed or removed: each finding names the posts, options or files to check. Clean them up in WP or in the database copy before the import, and check the administrator accounts wp:check lists as well.

Content

content_raw keeps the original HTML. blocks holds the content as a tree of {name, attrs, innerHTML, innerBlocks}, ready to render:

<x-wp-blocks :blocks="$post->blocks" />

Block content is parsed from its comment markers. Malformed markers never fail an import, they stay plain HTML. Content without markers is classic content: it gets paragraphs and line breaks and ends up as a single core/freeform block. References to reusable blocks are replaced by their content.

Links to the old site are rewritten. Upload URLs, including resized variants, point to the new media files. Post links point to the URL the resolver returns, by default from the patterns in the urls section of the configuration. The page WP shows on the front page keeps / as its address, whatever the pattern for pages says. For routes those patterns cannot express, implement ItsJustVita\WpMigrator\Content\Urls\UrlResolver and set it as urls.resolver. New URLs are built from the source site, so a link works even when its target is imported later in the same run. Whatever cannot be resolved stays in place and is listed in the report.

The stored HTML comes from the old site and is rendered as it is, the same way WP treats post content. Only import sites whose authors you trust.

Rendering

Every common core block has its own view. They output the stored HTML, including the wp-block-* classes. The package ships no CSS, so style those classes or publish the views and write your own markup:

php artisan vendor:publish --tag=wp-migrator-views

Views receive $block, $attrs and $content, which is the stored HTML with inner blocks already rendered. $block->unwrapped() returns the HTML inside the outermost element:

{{-- resources/views/vendor/wp-migrator/blocks/heading.blade.php --}}
<h{{ $attrs['level'] ?? 2 }} class="text-2xl">{!! $block->unwrapped() !!}</h{{ $attrs['level'] ?? 2 }}>

A block from another namespace looks for a view of its name, so acme/hero uses blocks/acme/hero.blade.php. You can also point a block at any view of your application:

WpMigrator::renderBlockUsing('acme/hero', 'components.hero');

Blocks without a view render their stored HTML and are listed in the report. Dynamic blocks such as core/latest-posts store no HTML, so they render nothing until you give them a view.

Elementor

Pages built with Elementor are converted from the element tree Elementor stores, not from the HTML copy it keeps in the content. Containers become groups, sections and columns become columns, and the common widgets become the matching core blocks: heading, text, image, button, video, divider, spacer, icon list, HTML, shortcode, image gallery, icon box, image box, testimonial, accordion, toggle and tabs. Global widgets and templates from the Elementor library are replaced by their content, up to 200 times per page and 10 levels deep. The design, such as colors, fonts and spacing, is not converted. Fields that hold HTML in Elementor, such as text, headings and the HTML widget, keep it just like post content does, while plain text fields are escaped and links that could run script are left out.

Every other widget, whether from Elementor Pro, another plugin or the theme, becomes a block named elementor/<widget> that holds all the widget's settings as attributes. Links in them point to the new URLs; IDs of media or posts stay those of the old site. Give such a widget a view and it renders like any other block:

{{-- resources/views/vendor/wp-migrator/blocks/elementor/acme-hero.blade.php --}}
<section class="hero">
    <h1>{{ $attrs['hero_title'] ?? '' }}</h1>
    @isset($attrs['cta']['url'])
        <a href="{{ $attrs['cta']['url'] }}">{{ $attrs['cta_text'] ?? 'More' }}</a>
    @endisset
</section>

The migration plan lists these widgets with the posts that use them, and wp:check reports the templates of the Elementor theme builder, such as headers, footers and popups, which are not migrated. Values of dynamic tags are not resolved. Set content.elementor to false to import the HTML copy instead; it is also used when the Elementor data of a page cannot be read.

Shortcodes

Handlers ship for caption, gallery, embed, video and audio. Unknown shortcodes stay in the content and are listed in the report with their number of occurrences and example posts. Add your own handler for them:

use ItsJustVita\WpMigrator\Content\Shortcodes\Shortcode;
use ItsJustVita\WpMigrator\Content\Shortcodes\ShortcodeContext;
use ItsJustVita\WpMigrator\Content\Shortcodes\ShortcodeHandler;

class NoticeHandler implements ShortcodeHandler
{
    public function render(Shortcode $shortcode, ShortcodeContext $context): string
    {
        return '<aside class="notice">'.$context->process($shortcode->content ?? '').'</aside>';
    }
}

WpMigrator::mapShortcode('notice', NoticeHandler::class);

Embeds make no network requests. YouTube and Vimeo get a player built from the URL, using the privacy-friendly YouTube domain, and everything else becomes a link.

After changing a handler, the URL patterns or other configuration, run wp:import --force to map unchanged rows again.

Custom fields

Post meta ends up in posts.fields. Keys starting with an underscore are internal and skipped unless you allow them in fields.allowed_internal_keys.

ACF fields are converted to typed values, using the field definitions stored in the source database:

ACF type Stored as
true/false, number, range boolean, integer or float
date picker, date time picker 2026-01-15, or ISO 8601 with the site's timezone
image, file, gallery IDs of the imported media
post object, relationship, page link IDs of what those posts were imported as
user, taxonomy IDs of the imported users and terms
repeater list of rows
flexible content list of rows, each with a layout key
group nested object
wysiwyg HTML with paragraphs, rendered shortcodes and rewritten links
url, link with links to the old site rewritten

Fields without a definition in the database, such as field groups registered only in PHP or local JSON, are copied as they are.

SEO

The per-post settings of Yoast SEO and Rank Math go into seo_meta: title, description, canonical URL, robots and the Open Graph fields. Template variables such as %%title%%, %%sep%%, %%sitename%% and %%excerpt%%, or their Rank Math equivalents, are resolved during the import. Variables that cannot be resolved are left out and listed in the report.

Most posts have no SEO settings of their own. The old site printed their title, description and robots from the settings of the plugin for the post type, such as the title template %%title%% %%sep%% %%sitename%%, and the import stores what those gave each post. A site without an SEO plugin printed the title of WP itself, "Title – Site name", which is stored the same way. So every page has the <title> it had before.

The robots meta is carried over the same way, without what changes nothing: index, follow and limits of -1. WP lets search engines show large image previews on every page (max-image-preview:large), and so do the plugins unless a setting of the post, its post type or the site says otherwise; that directive is stored with each post, next to noindex, nofollow and the like. Pages without a model, such as archives, get no robots meta from <x-wp-seo>; add one to your layout if you want it there too. These are fixed texts: when a post gets a new title later, change its SEO title too, or clear it. Set seo.site_defaults to false to import only what a post sets itself.

Render the tags in your layout:

<head>
    <x-wp-seo :model="$post" />
</head>

The title falls back to the model's title. SEO settings attach to whatever model a post was mapped onto. Add the ItsJustVita\WpMigrator\Models\Concerns\HasSeoMeta trait to your own models to eager load them with ->with('seo').

Menus

Classic menus become rows in menus with their theme locations, and their items rows in menu_items, nested and in order. Block themes keep their menus as navigation blocks; each of those becomes a menu too. A menu item that links to a post or term gets its new URL and a linkable relation to the imported model, so you can render menus straight from the database:

@foreach (\ItsJustVita\WpMigrator\Models\Menu::where('slug', 'main')->first()?->items->whereNull('parent_id') ?? [] as $item)
    <a href="{{ $item->url }}" @if ($item->target) target="{{ $item->target }}" @endif>{{ $item->title }}</a>
@endforeach

Links to post type archives have no new URL and are listed in the report. Like WP, the import leaves out menu items that link to drafts, private, scheduled, trashed or deleted posts; the entries below such an item move up one level. It drops links that could run script, such as javascript: URLs.

Comments

Comments are only imported when you turn them on with comments.enabled. Approved and pending comments are imported, threaded, attached to whatever model their post became. Spam, trash, pingbacks and trackbacks are left out, and so are IP addresses and user agents.

Comments come from visitors, so their HTML is reduced to the tags WP allows in comments, such as links, emphasis and quotes, and author URLs other than web addresses are dropped. Escape what you show with {{ }} anyway, except the content, which is safe to output with {!! !!}.

Users and passwords

Users go into your application's user model. Original password hashes are stored unchanged. A user whose email address already exists in your application is linked to that record, and the import never changes it. Roles and attributes are mapped in the users section of the configuration.

Every imported user can log in with their old password, so check the accounts before the import, especially on a site that was hacked: an attacker's account would come along with a working password. wp:check lists the administrators with their email address and registration date. Leave accounts out by ID, login or email address:

// config/wp-migrator.php
'users' => [
    'excluded' => ['intruder', 'someone@example.com', 10],
],

A number is an ID; a string of digits is tried as an ID, a login and an email address, since logins can be numbers too. wp:check and the import report name entries that match no user. Posts of an excluded user are imported without an author. An account that an earlier run imported stays in your application until you delete it; the report warns about it.

To let imported users log in with their old password, switch Laravel to the wordpress hashing driver:

HASH_DRIVER=wordpress

It verifies phpass hashes from WP before 6.8 and the prefixed bcrypt hashes from WP 6.8 and later. Plain MD5 hashes from very old installations are only accepted with passwords.allow_md5. Like the WP login, it ignores spaces around the password. Everything else, including every new hash, is handled by the driver in passwords.driver, bcrypt by default.

Laravel's login replaces a WP hash with a regular one at the first successful login, as long as hashing.rehash_on_login is on, which is the default. This works with Auth::attempt(), the starter kits and Fortify. If you authenticate users yourself, for example with Fortify::authenticateUsing(), check the password with Hash::check() and rehash it when Hash::needsRehash() says so.

See how many users still have a WP hash:

php artisan wp:password-stats

Redirects

The redirects importer runs last. It works out the URLs of the old site from its permalink settings: posts, pages with their hierarchy, custom post types, category, tag and author archives, attachment pages, and query URLs such as /?p=123. Each one gets a redirect to its new URL from the URL resolver, unless the URL stays the same. Attachment pages redirect to the file. The address the page on the front page had under its own slug redirects to /, and a site without posts gets no redirects for category, tag and author archives, which showed nothing. Set the archive patterns in urls.term_patterns and urls.author_pattern, or set them to null to leave those archives out.

Register the middleware globally, so it also sees requests no route matches. It answers a 404 for an old path with its redirect and counts the hit:

// bootstrap/app.php
use ItsJustVita\WpMigrator\Http\Middleware\RedirectMissingPages;

->withMiddleware(function (Middleware $middleware) {
    $middleware->append(RedirectMissingPages::class);
})

For many redirects, or to keep them out of PHP, export them for the web server:

php artisan wp:redirects:export --format=nginx --output=redirects.conf
php artisan wp:redirects:export --format=apache
php artisan wp:redirects:export --format=csv

Custom mappers

Every source row passes through a mapper. Register your own per post type or taxonomy in a service provider:

use ItsJustVita\WpMigrator\Facades\WpMigrator;

WpMigrator::mapPostType('event', EventMapper::class);
WpMigrator::mapTaxonomy('genre', GenreMapper::class);

A mapper receives a source object and an import context, and returns the model it persisted, or null to skip the row. A SourcePost also carries the transformed content in $post->blocks:

use Illuminate\Database\Eloquent\Model;
use ItsJustVita\WpMigrator\Import\ImportContext;
use ItsJustVita\WpMigrator\Import\SourceType;
use ItsJustVita\WpMigrator\Mapping\PostMapper;
use ItsJustVita\WpMigrator\Source\Dto\SourcePost;

class EventMapper implements PostMapper
{
    public function map(SourcePost $post, ImportContext $context): ?Model
    {
        $event = $context->existing(SourceType::Post, $post->id, Event::class) ?? new Event;

        $event->fill([
            'title' => $post->title,
            'starts_at' => $post->meta->get('starts_at'),
        ])->save();

        return $event;
    }
}

Migrating a site, step by step

  1. Prepare. Get a copy of the WP database and the wp-content/uploads directory, ideally with the theme next to it in wp-content/themes. Import the dump into a database the new application can read, add the connection, set source.uploads_path, and run php artisan wp:check. It shows what the site contains and which content the package does not migrate.
  2. Plan. Run php artisan wp:inventory and read docs/wp-migration-plan.md. Before the first import, check the administrator accounts and the suspicious content it lists, leave out post types that hold data rather than content, and decide on the URL patterns in the urls section of the configuration: links in the content, menu items and redirects are built from them.
  3. Import. Run php artisan wp:import --dry-run, read the report in storage/logs, then run php artisan wp:import. The report lists unknown shortcodes, blocks without a view and links it could not resolve.
  4. Build the frontend. Run php artisan wp:scaffold for a working start: routes, a controller and plain views for everything in the plan. Then work through the plan: style the views, give blocks and widgets their markup and write shortcode handlers. Run php artisan wp:import --force after changing handlers, mappers or URL patterns, so unchanged rows are mapped again.
  5. Import the changes. Shortly before going live, take a fresh copy of the database and the uploads and run php artisan wp:import again. It only brings over what changed. Add --prune to also remove what was deleted or trashed on the old site in the meantime; --dry-run --prune shows first what would go.
  6. Switch. Set HASH_DRIVER=wordpress, register the RedirectMissingPages middleware or export the redirects for the web server, point the DNS at the new application, and keep the old site and its database as a backup. With the middleware, the hits column of redirects shows which old URLs are still requested, and php artisan wp:password-stats shows how many users still have an old hash.

Versioning

The package follows Semantic Versioning. The public API is:

  • the Artisan commands and their options
  • the configuration keys in config/wp-migrator.php
  • the WpMigrator facade and the interfaces it registers: mappers, shortcode handlers and the URL resolver
  • the models, their tables and columns, and the DTOs mappers receive
  • the Blade components <x-wp-blocks> and <x-wp-seo>, the block view names and the variables they receive
  • the wordpress hashing driver and the RedirectMissingPages middleware

Everything else, such as the importers, readers and the theme scanner, is internal and may change in a minor version. So may the wording of the import report and the migration plan, and the files wp:scaffold writes; files it wrote earlier stay as they are.

Development

composer install
composer test
composer analyse
composer lint

The tests use SQLite by default. SQLite accepts unknown column names in some queries, so also run them against MySQL or MariaDB before relying on a change to a source query:

WP_MIGRATOR_TEST_DB_DRIVER=mysql \
WP_MIGRATOR_TEST_DB_HOST=127.0.0.1 \
WP_MIGRATOR_TEST_DB_PORT=3306 \
WP_MIGRATOR_TEST_DB_DATABASE=wordpress \
WP_MIGRATOR_TEST_DB_USERNAME=root \
WP_MIGRATOR_TEST_DB_PASSWORD=root \
composer test

These tests drop every table in the given database and in a database called wp_migrator_target, so point them at a throwaway server. They also import a complete site built with a real WordPress installation, twice, and check that the second run changes nothing. Rebuild that site after changing its content in tests/Fixtures/wordpress/content.php:

tests/Fixtures/wordpress/build.sh

Licence

MIT. See LICENSE.md.