Import Fixer
WP CLI utilities for fixing up WXR imports used in site merges, partial imports, etc.
by Spencer Cameron-Morin, Chris Hardie, Automattic · github.com/a8cteam51/wordpress-importer-fixers · website
Install
No release zip yet. The repository archive installs, but the folder name will carry the branch suffix and updates will not flow:
wp plugin install https://github.com/a8cteam51/wordpress-importer-fixers/archive/refs/heads/trunk.zipReadme
WordPress Import Fixers
WordPress Import Fixers is a WordPress plugin that registers wp import-fixer
WP-CLI subcommands for cleaning up non-trivial WordPress imports, including WXR
imports used for site merges and partial imports.
The plugin has no wp-admin user interface. It exits unless it is loaded in a WP-CLI request.
Repository Contents
import-fixer.phpcontains the plugin header, theImport_FixerWP_CLI_Commandclass, and thewp import-fixercommand registration.README.mddocuments the command behavior and the import metadata each command expects..gitignoreexcludes local operating-system and IDE files.
There are no Composer, npm, CI, lint, test, build, or deployment files tracked in this repository.
Requirements
- WordPress with WP-CLI available.
- A WordPress environment where this repository can be installed as a plugin.
- Imported content metadata required by the command being run, as described below.
Installation
This plugin is not available in the WordPress.org plugin directory. Install it
by placing this repository in a site's plugins directory, then activate the
plugin.
Because the plugin only registers WP-CLI commands, there are no user-facing tools in wp-admin after activation.
WP-CLI Commands
All commands are registered under wp import-fixer.
fix-thumbnails-contextually
wp import-fixer fix-thumbnails-contextually [--origin=<import-origin>]
Fixes featured image references after an import where original post and attachment IDs no longer match the IDs assigned on the target site.
The command expects:
- Posts and attachments to have
_original_import_originpost meta. - Thumbnail attachments to have
_original_post_idpost meta. - Posts with thumbnails to have
_original_thumbnail_idpost meta.
When --origin is supplied, only that import origin is processed. Without it,
the command processes all origins found in _original_import_origin post meta.
fix-galleries-contextually
wp import-fixer fix-galleries-contextually [--origin=<import-origin>]
Rewrites [gallery] shortcode ids values so gallery attachments point to the
attachments imported into the target site. Before replacing a gallery shortcode,
the command stores the original shortcode in _old_gallery_1, incrementing the
suffix for additional galleries in the same post.
The command expects:
- Posts and attachments to have
_original_import_originpost meta. - Gallery attachments to have
_original_post_idpost meta.
When --origin is supplied, only that import origin is processed. Without it,
the command processes all origins found in _original_import_origin post meta.
fix-media-urls
wp import-fixer fix-media-urls [--origin=<import-origin>]
Replaces source-site media URLs in post content with the current attachment URLs
for attachments already imported into the target site. It also handles image URL
variants with WordPress dimension suffixes such as -123x456.
The command expects:
- Posts and attachments to have
_original_import_originpost meta. - Attachments to have
_original_import_urlpost meta containing the media URL from the source site.
When --origin is supplied, only that import origin is processed. Without it,
the command processes all origins found in _original_import_origin post meta.
import-external-images
wp import-fixer import-external-images --list [--post_type=<post-type|any>]
wp import-fixer import-external-images --domain=<domain> [--protocol=<http|https>] [--post_type=<post-type|any>]
wp import-fixer import-external-images --all-domains [--post_type=<post-type|any>]
wp import-fixer import-external-images --rewind
Searches post content for external image URLs, sideloads matching images into
the media library, and replaces the source URLs with the new local attachment
URLs. It records imported image replacements in _added_via_script_backup_meta
so --rewind can reverse replacements and delete attachments imported by this
command.
Options:
--listlists external image domains found in post content without importing images.--domain=<domain>imports images from one domain.--protocol=<http|https>supplies the protocol used when relative image URLs are made absolute for a specified domain. The default ishttps.--all-domainsimports images from any external domain.--post_type=<post-type|any>limits processing to one post type, or uses all public non-attachment post types when set toany. The default ispost.--rewindreverses replacements made by this command and deletes attachments imported by it.
Use either --domain or --all-domains when importing. The command does not
support import origins.
fix-post-hierarchy-contextually
wp import-fixer fix-post-hierarchy-contextually
Fixes post parent references after an import where original parent and child IDs no longer match the IDs assigned on the target site.
The command expects:
- Posts to have
_original_import_originpost meta. - Posts to have
_original_post_idpost meta. - Posts with parents to have
_original_parent_idpost meta.
This command processes all origins found in _original_import_origin post meta.
fix-comment-count
wp import-fixer fix-comment-count
wp import-fixer fix-comment-count --url=example.test
Recalculates comment counts for published posts in batches of 500. Use WP-CLI's
standard --url option when running against a specific site in a multisite
installation.
Import Origins
Several commands use an import origin to scope fixes to a specific set of data.
The origin is the _original_import_origin post meta value attached to imported
posts and attachments.
The value can be any string, but it should identify the export batch clearly. For example:
20180831154400-myoldsite-201012to201512
Using --origin where supported is recommended for large sites because it
limits processing to one import batch. Commands that support --origin process
all discovered origins when the option is omitted.
Maintenance Notes
- Keep command documentation aligned with the docblocks and implementations in
import-fixer.php. - The repository does not include automated tests or linting configuration.
- No license file or package metadata is tracked in this repository.