Skip to content

WP-CLI commands ​

Find the WP-CLI command for each job, such as importing, backing up or masking links. Know what each command changes.

Link Manager Pro has 12 WP-CLI commands, all starting with wp link-manager-pro. Nine are for everyday work: import from another plugin, back up and restore, mask or restore the links in your posts, replace old shortcodes and old prefixes, delete old clicks and remove all plugin data. Three look after the database. WP-CLI is WordPress's command line, which many hosts offer over SSH. wp help link-manager-pro <command> lists the options of each command. This page adds their defaults and what they change.

Before you start ​

You need WP-CLI on your server and a fresh backup, because most commands, apart from a dry run, can change your site.

  • Run the commands from your WordPress folder, or add --path=/path/to/wordpress.
  • Back up first. Go to Link Manager › Settings › Backup & restore, select Backup, keep Posts and pages ticked, then select Back up now (Backup and restore). Or run backup export.
  • You don't need --user, except for backup restore with posts in --items (restore). Without it, WP-CLI saves posts without WordPress's HTML filter. One exception: a pending post that already has a slug is skipped, because saving it would clear the slug. If you add --user, name an account that can publish posts and unfiltered HTML (on multisite, a super admin). Otherwise posts are skipped where the filter would remove markup for that account (changes to formatting alone don't count).
  • On a multisite network, choose the site with --url=<site address>.
  • Type option names exactly as this page spells them. WP-CLI stops a command with a mistyped option, such as --dryrun, before it runs: Error: Parameter errors: unknown --dryrun parameter. Nothing changes. Only the commands with no options (migrate and migrate:status) accept extra options and ignore them.

The commands at a glance ​

Each command does one job. Run a command that has a dry run with --dry-run first. The first table holds the everyday commands.

CommandWhat it doesDry runAsks first
importImports from Pretty Links, ThirstyAffiliates or BetterLinksRun it with no options to see what it foundYes
backup exportWrites a backup fileNoneNo
backup restoreRestores items from a backup fileNoneYes
replace-shortcodesReplaces [prettylink], [thirstylink] and <ta> in posts with links--dry-runYes
replace-prefix-linksMoves short links in posts from an old prefix to the current one, or affiliate links to the affiliate prefix--dry-runYes
linkTurns links in your posts into short links--dry-run (counts posts only)Yes
unlinkPuts the original links back in your posts--dry-runYes
purge-clicksDeletes click records older than a number of daysNoneNo
uninstallDeletes all plugin data and deactivates the pluginNoneYes

The database and maintenance commands come next.

CommandWhat it doesDry runAsks first
migrateCreates missing plugin tables and updates existing onesNoneNo
migrate:statusShows which migration tables exist and have every columnNot needed: it changes nothingNo
migrate-link-markersMoves a leftover link attribute out of post content--dry-runYes

Every command that asks first skips the question with --yes, except uninstall, which also needs --delete-data. wp help link-manager-pro lists them all, with backup export and backup restore under backup. Scripting details are on WP-CLI for developers.

Import from another plugin with import ​

wp link-manager-pro import runs the same import as Link Manager › Settings › Migration, from the command line. Without options, it lists the plugins whose data it found and what each holds, then stops without importing anything. The full steps, items and examples are on Migrate to Link Manager Pro.

bash
wp link-manager-pro import

On a site with data from all three plugins, the list looks like this (simplified; a terminal draws it as a table):

text
Source       Plugin             Data
betterlinks  BetterLinks        50 links, 5 categories, 4 tags, 776 clicks, 2 passwords, 3 keywords, 4 geo_rules
prettylinks  Pretty Links       1,560 links, 8,957 clicks, 4 categories, 3 tags
thirstyaff   ThirstyAffiliates  47 links, 11 categories, 635 clicks, 2 keywords, 3 rules

Error: Specify a source with --source=<tag>. See detected plugins above.
OptionValuesDefault
--sourcebetterlinks, prettylinks, thirstyaffNone: lists what it found and stops
--itemsItems, such as links,clicksEvery item with data, never settings
--conflictskip or overwriteskip
--affiliatessuggested, none or domainssuggested
--yesA flag, no valueOff

--items and --affiliates take comma-separated lists; the items each source offers are on Migrate from Pretty Links, Migrate from ThirstyAffiliates and Migrate from BetterLinks. --yes skips the question Proceed with migration?. With skip, your short link stays as it is and the imported link gets a new slug; with the same destination, the two count as one link. overwrite is the browser's Update a short link with the same slug and destination with the imported settings (its clicks are kept).

WARNING

An import writes to your site and can't be undone, so back up first.

  • With --conflict=overwrite, a short link of yours with the same slug and the same destination takes the imported settings. Its auto-linking settings stay as they were. A link with the same slug and another destination stays as it is, and the imported link gets a new slug.
  • With settings in --items, the source's settings replace some of yours, including your Default redirect type.
  • With keywords, auto-linking switches on for those links, so your posts can show new auto-links right away.
bash
wp link-manager-pro import --source=prettylinks

The run shows a progress bar, then a Migrated, Skipped and Failed count per data type, errors, notes and a Link check: line. When posts still use old shortcodes, it says how many and suggests replace-shortcodes --dry-run, then ends with Success: Migration completed successfully.

After a ThirstyAffiliates import, while your Affiliate link prefix is empty, it also prints a hint before that last line. The hint names ThirstyAffiliates' own prefix, recommends by default, and the command that moves the links in your posts. It saves nothing and asks nothing (Use your ThirstyAffiliates prefix for affiliate links):

text
Use /recommends/ for affiliate links: set it as "Affiliate link prefix" in Settings > General.
Then move the affiliate links in posts with: wp link-manager-pro replace-prefix-links --affiliate --dry-run

Back up from the command line with backup export ​

wp link-manager-pro backup export writes the same backup file as Link Manager › Settings › Backup & restore, straight to a file on the server. It has no upload size limit and doesn't ask first.

OptionDefaultWhat it does
--itemsAll 12 itemsComma-separated: categories, tags, links, link_rules, clicks, affiliates, campaigns, link_health, redirects, settings, webhooks, posts.
--filelink-manager-pro-backup-<date>-<time>.json in the current folderWhere to write the file. An existing file is never overwritten: the command stops and asks you to choose another --file.
bash
wp link-manager-pro backup export --file=/tmp/links-backup.json

It ends with Success: Backup written to <file> (N records, SIZE). What the file holds is on Back up and restore.

Restore a backup with backup restore ​

wp link-manager-pro backup restore <file> restores items from a backup file, like Restore on the backup screen, with no upload limit.

OptionDefaultWhat it does
<file>RequiredThe backup .json file.
--itemsEvery item except posts and webhooksComma-separated, the same names as backup export.
--yesOffSkips the question, which names the items and the file.

Posts are saved as a user, so to restore them add posts to --items and --user=<administrator>. Without it, the command stops with an error.

WARNING

The chosen items replace your current data, and a finished restore can't be undone, so make a backup first. Items you don't choose are kept. If a restore stops partway, it rolls back and your data stays as it was. Posts and settings it can't restore are skipped and listed in the notes.

bash
wp link-manager-pro backup restore /tmp/links-backup.json --items=links,clicks

It ends with Success: Restore finished: N records. A restore stopped part-way can be resumed or rolled back on the backup screen (Back up and restore).

Replace old shortcodes with replace-shortcodes ​

wp link-manager-pro replace-shortcodes replaces [prettylink], [thirstylink] and <ta> in your posts with normal links to the imported short links, 25 posts at a time. It's the same replacement as Review and replace on the Migration screen.

OptionWhat it does
--dry-runCounts the shortcodes and posts that would change, lists the posts a real run would skip, and changes nothing. It never asks.
--yesSkips the question before a real run.
bash
wp link-manager-pro replace-shortcodes --dry-run

WARNING

The real run edits your posts. Each post's old content is saved as a revision first, but only where WordPress keeps revisions, so back up first.

bash
wp link-manager-pro replace-shortcodes

What each shortcode becomes and how to undo a replacement are on Replace old shortcodes.

wp link-manager-pro replace-prefix-links changes your own short links in posts from a prefix you used before to the current Short link prefix or Internal link prefix. With --affiliate, it moves only links to your affiliates' domains, to your Affiliate link prefix. Only links whose slug is an existing short link change. It's the command-line side of updating links after a prefix change (Change your short link prefix).

OptionDefaultWhat it does
--fromEvery previous prefix the plugin remembersMoves only this prefix, for example link. It must not be a prefix in use now.
--affiliateOffMoves only links to an affiliate's domain, from any of your prefixes to the Affiliate link prefix. With that prefix empty, it moves links under a previous affiliate prefix back to the link prefix. It can't be combined with --from.
--dry-runOffCounts the links and posts that would change. It never asks.
--yesOffSkips the question before a real run.

WARNING

The real run edits your posts. Each post's old content is saved as a revision first, but only where WordPress keeps revisions, so back up first. Links in page-builder data, such as Elementor, are listed but not changed.

bash
wp link-manager-pro replace-prefix-links --dry-run
wp link-manager-pro replace-prefix-links --affiliate --dry-run

It ends with Success: Dry run: N link(s) would be updated in N post(s). A real run says Updated N link(s) in N post(s). instead. With --affiliate, it first prints Affiliate links under: /link/, /go/ with the prefixes it scans. With none to scan, it says No affiliate prefix is set and none was used before: nothing to update.

wp link-manager-pro link turns the links in your posts into short links. It's the same scan as Scan posts, which opens from Scan my site on the Dashboard, and it runs whether Mask links when saving posts is on or off.

It checks published, scheduled and private posts and pages; drafts and pending posts are left alone. Full links to other sites become short links, and links to your own pages only while Mask internal links is on. A destination that already has a short link reuses it. The rules are on General settings.

OptionDefaultWhat it does
--dry-runOffCounts the posts it would check, by status. It doesn't say which links would change.
--per-batch100Posts loaded at a time. Each batch prints Scanned X/Y posts...
--yesOffSkips the question, which names how many posts it will check.
bash
wp link-manager-pro link --dry-run

A dry run answers like Success: Dry run: 9798 post(s) (9686 published, 1 scheduled, 111 private) would be scanned for masking. Before the real run, compare the count in its question with that line, and answer y only if they match.

WARNING

This edits your posts, as the Scan posts dialog warns. Back up first; WordPress keeps a revision of each post only where revisions are on. To undo it, use unlink.

bash
wp link-manager-pro link

It ends with Masking complete. Posts updated: N, links turned into short links: N (new short links: N).

wp link-manager-pro unlink puts the original links back in posts where Link Manager Pro masked them, on save, with Scan posts or with link. There's no button for this in the admin.

  • Each masked link goes back to the address it had when it was masked, even if you changed the short link's destination since.
  • Short links you added yourself, for example from the editor, stay, unless you add --restore-shortlinks.
  • The rel values masking added stay, unless you add --strip-rel.
  • The short links stay in your Short Links list, with their clicks.
  • Links under your current Short link prefix, Internal link prefix or Affiliate link prefix are restored, and so are links under a prefix you used before (General settings).
OptionDefaultWhat it does
--scopescannedscanned: posts of any type where masking was recorded. all: every published, draft, private, scheduled or pending post of the types in --post-types.
--post-typespost,pageComma-separated. Used only with --scope=all.
--idsNoneComma-separated post IDs. Restores only those posts.
--per-batch200Posts handled per batch.
--restore-shortlinksOffAlso replaces your own short links with their current destination. A deleted short link stays and counts as unresolved.
--strip-relOffRemoves the whole rel attribute from each restored link, including values you wrote, such as your own nofollow.
--disable-autolinkOffAfter a real run that found posts, turns off Link keywords in posts automatically, which pauses all auto-linking (Auto-linking settings).
--dry-runOffCounts the posts and links that would change. Posts a real run would skip are reported as skipped.
--yesOffSkips the question, which names how many posts it will check.

First turn off Mask links when saving posts under Link Manager › Settings › General. While it's on, the next save of a restored post masks its links again.

bash
wp link-manager-pro unlink --dry-run

It answers like Success: Posts would change: 9545. Links restored: 26817, short links kept: 3034, unresolved: 0. A dry run runs the same save checks as a real run. Posts a real run would skip are counted as skipped, with one warning per cause, and not in the post count.

WARNING

This edits your posts. Back up first; WordPress keeps a revision of each post only where revisions are on. Read the post count in the question before you answer y: leave out --ids and the run covers every post in the scope (by default, every post where masking was recorded). A mistyped option, such as --id, stops the command before it runs. Add --yes only to a command whose dry run looked right.

bash
wp link-manager-pro unlink

When links can't be resolved (their short link was deleted and nothing records where they went), a warning says how many. Check those posts by hand.

Delete old clicks now with purge-clicks ​

wp link-manager-pro purge-clicks deletes click records older than Keep click data for under Link Manager › Settings › Tracking, right away. It deletes the same records as the daily clean-up (Keep click data for), runs until it's done, and doesn't ask first.

OptionDefaultWhat it does
--daysKeep click data forDeletes records older than this many days instead, for this run only. Your setting doesn't change.

WARNING

Deleted click records are gone for good, and this command doesn't ask first. Without --days, the run deletes by your Keep click data for setting. A mistyped option, such as --day=30, stops the command before it deletes anything. If you might want the old data, make a backup with Clicks ticked first (Backup and restore).

bash
wp link-manager-pro purge-clicks --days=365

It ends with Success: Purged N click records older than 365 days. All-time clicks and a redirect's Hits don't go down. With Keep click data for at 0 (the default) and no --days, it stops with No retention period set. and deletes nothing.

Remove all plugin data with uninstall ​

wp link-manager-pro uninstall --delete-data deletes all Link Manager Pro data from the site straight away, then deactivates the plugin. It removes the same data as deleting the plugin with Delete all data when the plugin is deleted on, whatever that switch says (Advanced settings). Without --delete-data, it does nothing.

WARNING

This deletes all short links, clicks, redirects, affiliates, reports and settings on the site for good. Back up first, and keep the file somewhere other than your site. Your posts keep their short link addresses, and those usually open a 404 page once the plugin is gone. To put the original links back first, turn off masking and run unlink --scope=all --restore-shortlinks (Uninstall and delete data).

On a multisite network, the plugin runs on each site separately (it can't be network-activated), so uninstall deletes the data of the site you name with --url and deactivates the plugin there only.

bash
wp link-manager-pro uninstall --delete-data

It lists what it removed, then says Plugin deactivated. and suggests wp plugin uninstall link-manager-pro, or activating the plugin again for a fresh install. The whole removal is on Uninstall and delete data.

Create missing tables with migrate ​

wp link-manager-pro migrate sets up the plugin's database tables: it creates any that are missing and brings existing ones up to the current layout, using WordPress's dbDelta function. None of the migration files deletes data. The plugin already does this when you activate or update it, so you rarely need it by hand.

bash
wp link-manager-pro migrate

It has no options. It prints Running migrations..., a Migrating: and Migrated: line for each of the 8 migration files, any errors, and Success: Migrations completed. The success line appears even when an error line came before it, so read the lines above it.

List the migration files with migrate:status ​

wp link-manager-pro migrate:status prints a table with the name, file and status of each migration. It checks your database for the table each migration creates, and for its columns. It changes nothing.

bash
wp link-manager-pro migrate:status

The Status column reads Ran when the migration's table exists with every column the migration defines. It reads Incomplete when the table lacks a column, Missing when the table doesn't exist, and Unknown when the migration file creates no table. After the table, a line per incomplete migration names the missing columns, followed by Run "wp link-manager-pro migrate" to add them. It has no options.

wp link-manager-pro migrate-link-markers cleans up posts that still carry a data-link-manager-pro-original attribute on masked links. That attribute put the link's original destination into your public page HTML. Link Manager Pro no longer adds it. The command removes it from the content and keeps the destination in a hidden post field (_lmp_link_map), which unlink can read later.

It looks at posts of every type except revisions, in any status, that contain the attribute. WordPress's save checks can skip a post. A warning then says how many posts were left as they were, one warning per cause.

OptionDefaultWhat it does
--dry-runOffPrints [dry-run] Post N: M marker(s) would be migrated. for each post and changes nothing. It never asks.
--per-batch200Posts loaded at a time. Values below 1 count as 1.
--yesOffSkips the question Strip leaked original-URL markers from post content and move them to protected post meta?
bash
wp link-manager-pro migrate-link-markers --dry-run

WARNING

The real run edits your posts. Back up first, and keep Posts and pages ticked (Back up and restore).

bash
wp link-manager-pro migrate-link-markers

It ends with Success: Scanned N post(s); migrated N post(s) and N link marker(s). A dry run says would migrate in place of migrated.

What has no command ​

Some jobs stay in the admin:

  • Link Health scans (Link Health).
  • Adding or listing redirects (Redirects). A BetterLinks import brings the page redirects made by its Simple 301 Redirects importer.
  • Changing settings, apart from the import settings item and unlink --disable-autolink.

Scheduled jobs are WordPress scheduled tasks, which wp cron event list shows: for example link_manager_pro_purge_clicks, and link_manager_pro_email_digest while the email digest is on (Notifications).

Get more out of it ​

A few command-line habits make big jobs safer.

  • Undo all masking before you remove the plugin. Turn off Mask links when saving posts, then run unlink --scope=all --restore-shortlinks --dry-run. If the counts look right, run it again without --dry-run, before uninstall. Your posts then link straight to the destinations.
  • Try one post first. wp link-manager-pro unlink --ids=123 restores only post 123 (this edits it). Open it and check the links before you run the whole site.
  • Clear a backlog of old clicks in one go. The daily clean-up works for about 25 seconds per run, so a large backlog takes days. Run purge-clicks once after you set Keep click data for (it deletes for good, with no question: back up first).
  • Split a large import. Import every item except clicks first, then --items=clicks on its own. Clicks are the one item every source adds in a later run.
  • If Pretty Links or BetterLinks had IP anonymizing on and your site has Anonymize IP addresses off, run --items=settings before you import clicks. It also replaces your Default redirect type (see the import Warning).

If something goes wrong ​

  • If link, unlink or migrate-link-markers warns that posts were skipped, then read the warning, which names one cause per line. "Changed during the run": run it again. "Would also change status or URL slug": check those posts in the editor. "Can't be edited by the --user account": run again without --user. "Would lose content": run as a user who can post unfiltered HTML (on multisite, a super admin). replace-shortcodes lists each skipped post with its reason instead.
  • If unlink leaves some short links in your posts, then you added them yourself (add --restore-shortlinks), or they use an old address kept from an import.
  • If import says No data from a supported plugin (Pretty Links, BetterLinks, ThirstyAffiliates) was found on this site., then none of that data is in this site's database. The old plugin doesn't need to be active. On a multisite network, check --url.
  • If purge-clicks says Another click purge is running. Try again in a few minutes., then wait a few minutes and run it again.
  • If a command ran without an option you typed, then check its spelling against the tables on this page.

More fixes are on Troubleshooting.